aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2006-09-29 04:59:06 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-09-29 12:18:06 -0400
commit684f978347deb42d180373ac4c427f82ef963171 (patch)
treedb9025d8c6b267565c7110e09b16193957186a48
parent6299a2dec89d22940e36832f15c0addfb77e6910 (diff)
[PATCH] Let WARN_ON/WARN_ON_ONCE return the condition
Letting WARN_ON/WARN_ON_ONCE return the condition means that you could do if (WARN_ON(blah)) { handle_impossible_case } Rather than if (unlikely(blah)) { WARN_ON(1) handle_impossible_case } I checked all the newly added WARN_ON_ONCE users and none of them test the return status so we can still change it. [akpm@osdl.org: warning fix] [akpm@osdl.org: build fix] Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Cc: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--include/asm-generic/bug.h32
-rw-r--r--include/asm-powerpc/bug.h12
2 files changed, 23 insertions, 21 deletions
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 8ceab7bcd8b4..a5250895155e 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -16,12 +16,15 @@
16#endif 16#endif
17 17
18#ifndef HAVE_ARCH_WARN_ON 18#ifndef HAVE_ARCH_WARN_ON
19#define WARN_ON(condition) do { \ 19#define WARN_ON(condition) ({ \
20 if (unlikely((condition)!=0)) { \ 20 typeof(condition) __ret_warn_on = (condition); \
21 printk("BUG: warning at %s:%d/%s()\n", __FILE__, __LINE__, __FUNCTION__); \ 21 if (unlikely(__ret_warn_on)) { \
22 dump_stack(); \ 22 printk("BUG: warning at %s:%d/%s()\n", __FILE__, \
23 } \ 23 __LINE__, __FUNCTION__); \
24} while (0) 24 dump_stack(); \
25 } \
26 unlikely(__ret_warn_on); \
27})
25#endif 28#endif
26 29
27#else /* !CONFIG_BUG */ 30#else /* !CONFIG_BUG */
@@ -34,21 +37,18 @@
34#endif 37#endif
35 38
36#ifndef HAVE_ARCH_WARN_ON 39#ifndef HAVE_ARCH_WARN_ON
37#define WARN_ON(condition) do { if (condition) ; } while(0) 40#define WARN_ON(condition) unlikely((condition))
38#endif 41#endif
39#endif 42#endif
40 43
41#define WARN_ON_ONCE(condition) \ 44#define WARN_ON_ONCE(condition) ({ \
42({ \
43 static int __warn_once = 1; \ 45 static int __warn_once = 1; \
44 int __ret = 0; \ 46 typeof(condition) __ret_warn_once = (condition);\
45 \ 47 \
46 if (unlikely((condition) && __warn_once)) { \ 48 if (likely(__warn_once)) \
47 __warn_once = 0; \ 49 if (WARN_ON(__ret_warn_once)) \
48 WARN_ON(1); \ 50 __warn_once = 0; \
49 __ret = 1; \ 51 unlikely(__ret_warn_once); \
50 } \
51 __ret; \
52}) 52})
53 53
54#ifdef CONFIG_SMP 54#ifdef CONFIG_SMP
diff --git a/include/asm-powerpc/bug.h b/include/asm-powerpc/bug.h
index f44b529e3298..978b2c7e84ea 100644
--- a/include/asm-powerpc/bug.h
+++ b/include/asm-powerpc/bug.h
@@ -70,9 +70,10 @@ struct bug_entry *find_bug(unsigned long bugaddr);
70 "i" (__FILE__), "i" (__FUNCTION__)); \ 70 "i" (__FILE__), "i" (__FUNCTION__)); \
71} while (0) 71} while (0)
72 72
73#define WARN_ON(x) do { \ 73#define WARN_ON(x) ({ \
74 if (__builtin_constant_p(x)) { \ 74 typeof(x) __ret_warn_on = (x); \
75 if (x) \ 75 if (__builtin_constant_p(__ret_warn_on)) { \
76 if (__ret_warn_on) \
76 __WARN(); \ 77 __WARN(); \
77 } else { \ 78 } else { \
78 __asm__ __volatile__( \ 79 __asm__ __volatile__( \
@@ -80,11 +81,12 @@ struct bug_entry *find_bug(unsigned long bugaddr);
80 ".section __bug_table,\"a\"\n" \ 81 ".section __bug_table,\"a\"\n" \
81 "\t"PPC_LONG" 1b,%1,%2,%3\n" \ 82 "\t"PPC_LONG" 1b,%1,%2,%3\n" \
82 ".previous" \ 83 ".previous" \
83 : : "r" ((long)(x)), \ 84 : : "r" (__ret_warn_on), \
84 "i" (__LINE__ + BUG_WARNING_TRAP), \ 85 "i" (__LINE__ + BUG_WARNING_TRAP), \
85 "i" (__FILE__), "i" (__FUNCTION__)); \ 86 "i" (__FILE__), "i" (__FUNCTION__)); \
86 } \ 87 } \
87} while (0) 88 unlikely(__ret_warn_on); \
89})
88 90
89#define HAVE_ARCH_BUG 91#define HAVE_ARCH_BUG
90#define HAVE_ARCH_BUG_ON 92#define HAVE_ARCH_BUG_ON