What to do with macros with do while (0) body

Philipp Hortmann philipp.g.hortmann at gmail.com
Sat Mar 19 03:25:34 EDT 2022


Hi all,

please support me in what to do with the below macro as checkpatch seems 
to hate them.

In this case the macro is unused. Just remove macro?

When the macro is used how to remove this checkpatch message:
CHECK: Macro argument reuse 'iobase' - possible side-effects?
Even when iobase is just used in this macro this message does not go away.

I do prefer to make a function out of such macros but what is kernel 
standard?

CHECK: Avoid CamelCase: <MACvWriteCRC16_128>
#864: FILE: drivers/staging/vt6655/mac.h:864:
+#define MACvWriteCRC16_128(iobase, byRegOfs, wCRC)		\

CHECK: Avoid CamelCase: <wCRC>
#864: FILE: drivers/staging/vt6655/mac.h:864:
+#define MACvWriteCRC16_128(iobase, byRegOfs, wCRC)		\

CHECK: Macro argument reuse 'iobase' - possible side-effects?
#864: FILE: drivers/staging/vt6655/mac.h:864:
+#define MACvWriteCRC16_128(iobase, byRegOfs, wCRC)		\
+do {								\
+	VNSvOutPortB(iobase + MAC_REG_PAGE1SEL, 1);		\
+	VNSvOutPortW(iobase + byRegOfs, wCRC);		\
+	VNSvOutPortB(iobase + MAC_REG_PAGE1SEL, 0);		\
+} while (0)

CHECK: Macro argument 'iobase' may be better as '(iobase)' to avoid 
precedence issues
#864: FILE: drivers/staging/vt6655/mac.h:864:
+#define MACvWriteCRC16_128(iobase, byRegOfs, wCRC)		\
+do {								\
+	VNSvOutPortB(iobase + MAC_REG_PAGE1SEL, 1);		\
+	VNSvOutPortW(iobase + byRegOfs, wCRC);		\
+	VNSvOutPortB(iobase + MAC_REG_PAGE1SEL, 0);		\
+} while (0)

CHECK: Macro argument 'byRegOfs' may be better as '(byRegOfs)' to avoid 
precedence issues
#864: FILE: drivers/staging/vt6655/mac.h:864:
+#define MACvWriteCRC16_128(iobase, byRegOfs, wCRC)		\
+do {								\
+	VNSvOutPortB(iobase + MAC_REG_PAGE1SEL, 1);		\
+	VNSvOutPortW(iobase + byRegOfs, wCRC);		\
+	VNSvOutPortB(iobase + MAC_REG_PAGE1SEL, 0);		\
+} while (0)

Thanks for your support.

Bye Philipp



More information about the Kernelnewbies mailing list