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

Greg KH greg at kroah.com
Sat Mar 19 03:38:40 EDT 2022


On Sat, Mar 19, 2022 at 08:25:34AM +0100, Philipp Hortmann wrote:
> 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?

Yes.

> 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?

Making it a function please.

> 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)

checkpatch is right here, this is a horrid macro and can cause problems
if used incorrectly.  Make this a function.

thanks,

greg k-h



More information about the Kernelnewbies mailing list