Skip to content

Commit

Permalink
Fix WARN_ON() on bitfield ops
Browse files Browse the repository at this point in the history
Alexey Dobriyan noticed that the new WARN_ON() semantics that were
introduced by commit 684f978 (to also
return the value to be warned on) didn't compile when given a bitfield,
because the typeof doesn't work for bitfields.

So instead of the typeof trick, use an "int" variable together with a
"!!(x)" expression, as suggested by Al Viro.

To make matters more interesting, Paul Mackerras points out that that is
sub-optimal on Power, but the old asm-coded comparison seems to be buggy
anyway on 32-bit Power if the conditional was 64-bit, so I think there
are more problems there.

Regardless, the new WARN_ON() semantics may have been a bad idea.  But
this at least avoids the more serious complications.

Cc: Alexey Dobriyan <adobriyan@sw.ru>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Al Viro <viro@ftp.linux.org.uk>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Linus Torvalds committed Aug 1, 2007
1 parent 2f63251 commit 8d4fbcf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions include/asm-generic/bug.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct bug_entry {

#ifndef HAVE_ARCH_WARN_ON
#define WARN_ON(condition) ({ \
typeof(condition) __ret_warn_on = (condition); \
int __ret_warn_on = !!(condition); \
if (unlikely(__ret_warn_on)) { \
printk("WARNING: at %s:%d %s()\n", __FILE__, \
__LINE__, __FUNCTION__); \
Expand All @@ -54,15 +54,15 @@ struct bug_entry {

#ifndef HAVE_ARCH_WARN_ON
#define WARN_ON(condition) ({ \
typeof(condition) __ret_warn_on = (condition); \
int __ret_warn_on = !!(condition); \
unlikely(__ret_warn_on); \
})
#endif
#endif

#define WARN_ON_ONCE(condition) ({ \
static int __warned; \
typeof(condition) __ret_warn_once = (condition); \
int __ret_warn_once = !!(condition); \
\
if (unlikely(__ret_warn_once)) \
if (WARN_ON(!__warned)) \
Expand Down
2 changes: 1 addition & 1 deletion include/asm-powerpc/bug.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
} while (0)

#define WARN_ON(x) ({ \
typeof(x) __ret_warn_on = (x); \
int __ret_warn_on = !!(x); \
if (__builtin_constant_p(__ret_warn_on)) { \
if (__ret_warn_on) \
__WARN(); \
Expand Down

0 comments on commit 8d4fbcf

Please sign in to comment.