diff mbox

[PATCHv2,1/4] DSPBRIDGE: Fix macros that break when inside an if/else

Message ID 1247488726-14960-1-git-send-email-ameya.palande@nokia.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Ameya Palande July 13, 2009, 12:38 p.m. UTC
From: Phil Carmody <ext-phil.2.carmody@nokia.com>

cp_{to,fm}_usr break if between an if and an else (with no {}).

http://www.faqs.org/faqs/C-faq/abridged/
10.4: What's the best way to write a multi-statement macro?
A:    #define Func() do {stmt1; stmt2; ... } while(0) /* (no trailing ;) */

Signed-off-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
---
 drivers/dsp/bridge/pmgr/wcd.c |   42 ++++++++++++++++++++++------------------
 1 files changed, 23 insertions(+), 19 deletions(-)

Comments

Ameya Palande July 13, 2009, 12:42 p.m. UTC | #1
I still get following warnings from checkpatch.pl:

WARNING: suspect code indent for conditional statements (0, 2)
#45: FILE: drivers/dsp/bridge/pmgr/wcd.c:151:
+do {						\
+  if (DSP_SUCCEEDED(status)) {			\

WARNING: suspect code indent for conditional statements (2, 4)
#46: FILE: drivers/dsp/bridge/pmgr/wcd.c:152:
+  if (DSP_SUCCEEDED(status)) {			\
+    if (unlikely((src) == NULL) ||		\

ERROR: code indent should use tabs where possible
#49: FILE: drivers/dsp/bridge/pmgr/wcd.c:155:
+        GT_1trace(WCD_debugMask, GT_7CLASS,^I\$

WARNING: suspect code indent for conditional statements (0, 2)
#57: FILE: drivers/dsp/bridge/pmgr/wcd.c:163:
+do {						\
+  if (DSP_SUCCEEDED(status)) {			\

WARNING: suspect code indent for conditional statements (2, 4)
#58: FILE: drivers/dsp/bridge/pmgr/wcd.c:164:
+  if (DSP_SUCCEEDED(status)) {			\
+    if (unlikely((dest) == NULL) ||		\

ERROR: code indent should use tabs where possible
#61: FILE: drivers/dsp/bridge/pmgr/wcd.c:167:
+        GT_1trace(WCD_debugMask, GT_7CLASS,^I\$

ERROR: code indent should use tabs where possible
#62: FILE: drivers/dsp/bridge/pmgr/wcd.c:168:
+          "copy_to_user failed, dest=0x%x\n", dest);^I\$

ERROR: code indent should use tabs where possible
#63: FILE: drivers/dsp/bridge/pmgr/wcd.c:169:
+        (status) = DSP_EPOINTER ;^I^I\$

total: 4 errors, 4 warnings, 48 lines checked

I have used 2 spaces instead of a tab for indentation so that line
won't exceed 80 columns limit, and we still maintain good amount of
readability with this macro.

Cheers,
Ameya.
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/dsp/bridge/pmgr/wcd.c b/drivers/dsp/bridge/pmgr/wcd.c
index 86812c6..da0467c 100644
--- a/drivers/dsp/bridge/pmgr/wcd.c
+++ b/drivers/dsp/bridge/pmgr/wcd.c
@@ -147,25 +147,29 @@ 
 
 /* Following two macros should ideally have do{}while(0) */
 
-#define cp_fm_usr(dest, src, status, elements)    \
-    if (DSP_SUCCEEDED(status)) {\
-	    if (unlikely(src == NULL) ||				\
-		unlikely(copy_from_user(dest, src, elements * sizeof(*(dest))))) { \
-		GT_1trace(WCD_debugMask, GT_7CLASS, \
-		"copy_from_user failed, src=0x%x\n", src);  \
-		status = DSP_EPOINTER ; \
-	} \
-    }
-
-#define cp_to_usr(dest, src, status, elements)    \
-    if (DSP_SUCCEEDED(status)) {\
-	    if (unlikely(dest == NULL) ||				\
-		unlikely(copy_to_user(dest, src, elements * sizeof(*(src))))) { \
-		GT_1trace(WCD_debugMask, GT_7CLASS, \
-		"copy_to_user failed, dest=0x%x\n", dest); \
-		status = DSP_EPOINTER ;\
-	} \
-    }
+#define cp_fm_usr(dest, src, status, elements)	\
+do {						\
+  if (DSP_SUCCEEDED(status)) {			\
+    if (unlikely((src) == NULL) ||		\
+      unlikely(copy_from_user(dest, src, (elements) * sizeof(*(dest))))) { \
+        GT_1trace(WCD_debugMask, GT_7CLASS,	\
+	  "copy_from_user failed, src=0x%x\n", src);	\
+      (status) = DSP_EPOINTER ;			\
+    }						\
+  }						\
+} while (0)
+
+#define cp_to_usr(dest, src, status, elements)	\
+do {						\
+  if (DSP_SUCCEEDED(status)) {			\
+    if (unlikely((dest) == NULL) ||		\
+      unlikely(copy_to_user(dest, src, (elements) * sizeof(*(src))))) { \
+        GT_1trace(WCD_debugMask, GT_7CLASS,	\
+          "copy_to_user failed, dest=0x%x\n", dest);	\
+        (status) = DSP_EPOINTER ;		\
+    }						\
+  }						\
+} while (0)
 
 /* Device IOCtl function pointer */
 struct WCD_Cmd {