Skip to content

Commit 8d4fbcf

Browse files
author
Linus Torvalds
committed
Fix WARN_ON() on bitfield ops
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>
1 parent 2f63251 commit 8d4fbcf

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

‎include/asm-generic/bug.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct bug_entry {
3333

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

5555
#ifndef HAVE_ARCH_WARN_ON
5656
#define WARN_ON(condition) ({ \
57-
typeof(condition) __ret_warn_on = (condition); \
57+
int __ret_warn_on = !!(condition); \
5858
unlikely(__ret_warn_on); \
5959
})
6060
#endif
6161
#endif
6262

6363
#define WARN_ON_ONCE(condition) ({ \
6464
static int __warned; \
65-
typeof(condition) __ret_warn_once = (condition); \
65+
int __ret_warn_once = !!(condition); \
6666
\
6767
if (unlikely(__ret_warn_once)) \
6868
if (WARN_ON(!__warned)) \

‎include/asm-powerpc/bug.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
} while (0)
9494

9595
#define WARN_ON(x) ({ \
96-
typeof(x) __ret_warn_on = (x); \
96+
int __ret_warn_on = !!(x); \
9797
if (__builtin_constant_p(__ret_warn_on)) { \
9898
if (__ret_warn_on) \
9999
__WARN(); \

0 commit comments

Comments
 (0)