Skip to content

Commit

Permalink
WARN_ON_SMP(): Add comment to explain ({0;})
Browse files Browse the repository at this point in the history
The define to use ({0;}) for the !CONFIG_SMP case of WARN_ON_SMP()
can be confusing. As the WARN_ON_SMP() needs to be a nop when
CONFIG_SMP is not set, including all its parameters must not be
evaluated, and that it must work as both a stand alone statement
and inside an if condition, we define it to a funky ({0;}).

A simple "0" will not work as it causes gcc to give the warning that
the statement has no effect.

As this strange definition has raised a few eyebrows from some
major kernel developers, it is wise to document why we create such
a work of art.

Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
  • Loading branch information
Steven Rostedt authored and Steven Rostedt committed Mar 28, 2011
1 parent 18bcd0c commit ccd0d44
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/asm-generic/bug.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ extern void warn_slowpath_null(const char *file, const int line);
#ifdef CONFIG_SMP
# define WARN_ON_SMP(x) WARN_ON(x)
#else
/*
* Use of ({0;}) because WARN_ON_SMP(x) may be used either as
* a stand alone line statement or as a condition in an if ()
* statement.
* A simple "0" would cause gcc to give a "statement has no effect"
* warning.
*/
# define WARN_ON_SMP(x) ({0;})
#endif

Expand Down

0 comments on commit ccd0d44

Please sign in to comment.