linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* checkpatch.pl: Wrong check SINGLE_STATEMENT_DO_WHILE_MACRO
@ 2012-08-02  8:00 Schrober
  2012-08-02 14:20 ` Andy Whitcroft
  0 siblings, 1 reply; 6+ messages in thread
From: Schrober @ 2012-08-02  8:00 UTC (permalink / raw)
  To: Joe Perches; +Cc: Andy Whitcroft, linux-kernel

Hi,

I think your check for SINGLE_STATEMENT_DO_WHILE_MACRO is wrong. Just to give 
an example:

#define foobar(x) \
	do { \
		if (pizza_ready(x)) \
			eat_pizza(x); \
	} while (0)


if (hungry(y))
	foobar(x);
else
	barfoo(x);

checkpatch does now complain about something like "WARNING: Single statement 
macros should not use a do {} while (0) loop"

But we would have an ambiguous else when the do-while is removed. The code 
works as expected with the do-while but the else is "attached" to the wrong 
"if" when the do-while is removed.

And yes, this example is made that easy to make it easy to understand. There 
are examples were static inline code would not work very well (vararg for 
example).

Please fix or remove your check. Otherwise some people will be start to 
overeagerly change these macros and break the kernel doing that.
-- 
Franz Schrober

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-08-02 22:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-02  8:00 checkpatch.pl: Wrong check SINGLE_STATEMENT_DO_WHILE_MACRO Schrober
2012-08-02 14:20 ` Andy Whitcroft
2012-08-02 15:26   ` [PATCH] checkpatch: Add control statement test to SINGLE_STATEMENT_DO_WHILE_MACRO Joe Perches
2012-08-02 16:23     ` Andy Whitcroft
2012-08-02 16:44       ` Schrober
2012-08-02 22:10         ` Stephen Rothwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).