blob: b8ba6941f587c7d12ac850f621826efd00107c35 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ASM_GENERIC_BUG_H
2#define _ASM_GENERIC_BUG_H
3
4#include <linux/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
Matt Mackallc8538a72005-05-01 08:59:01 -07006#ifdef CONFIG_BUG
Jeremy Fitzhardinge7664c5a2006-12-08 02:36:19 -08007
8#ifdef CONFIG_GENERIC_BUG
9#ifndef __ASSEMBLY__
10struct bug_entry {
11 unsigned long bug_addr;
12#ifdef CONFIG_DEBUG_BUGVERBOSE
13 const char *file;
14 unsigned short line;
15#endif
16 unsigned short flags;
17};
18#endif /* __ASSEMBLY__ */
19
20#define BUGFLAG_WARNING (1<<0)
21#endif /* CONFIG_GENERIC_BUG */
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#ifndef HAVE_ARCH_BUG
24#define BUG() do { \
Harvey Harrisond5c003b2008-10-15 22:01:24 -070025 printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 panic("BUG!"); \
27} while (0)
28#endif
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#ifndef HAVE_ARCH_BUG_ON
Alexey Dobriyan2a41de42007-07-17 04:03:56 -070031#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#endif
33
Olof Johansson3a6a62f92008-01-30 13:32:50 +010034#ifndef __WARN
Arjan van de Ven79b4cc52008-01-30 13:32:50 +010035#ifndef __ASSEMBLY__
Arjan van de Vena8f18b92008-07-25 01:45:53 -070036extern void warn_slowpath(const char *file, const int line,
37 const char *fmt, ...) __attribute__((format(printf, 3, 4)));
Arjan van de Ven79b4cc52008-01-30 13:32:50 +010038#define WANT_WARN_ON_SLOWPATH
39#endif
Ingo Molnarec5679e2008-11-28 17:56:14 +010040#define __WARN() warn_slowpath(__FILE__, __LINE__, NULL)
41#define __WARN_printf(arg...) warn_slowpath(__FILE__, __LINE__, arg)
Arjan van de Vena8f18b92008-07-25 01:45:53 -070042#else
Ingo Molnarec5679e2008-11-28 17:56:14 +010043#define __WARN_printf(arg...) do { printk(arg); __WARN(); } while (0)
Olof Johansson3a6a62f92008-01-30 13:32:50 +010044#endif
45
46#ifndef WARN_ON
Herbert Xu684f9782006-09-29 01:59:06 -070047#define WARN_ON(condition) ({ \
Linus Torvalds8d4fbcf2007-07-31 21:12:07 -070048 int __ret_warn_on = !!(condition); \
Olof Johansson3a6a62f92008-01-30 13:32:50 +010049 if (unlikely(__ret_warn_on)) \
50 __WARN(); \
Herbert Xu684f9782006-09-29 01:59:06 -070051 unlikely(__ret_warn_on); \
52})
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#endif
54
Arjan van de Vena8f18b92008-07-25 01:45:53 -070055#ifndef WARN
56#define WARN(condition, format...) ({ \
57 int __ret_warn_on = !!(condition); \
58 if (unlikely(__ret_warn_on)) \
59 __WARN_printf(format); \
60 unlikely(__ret_warn_on); \
61})
62#endif
63
Matt Mackallc8538a72005-05-01 08:59:01 -070064#else /* !CONFIG_BUG */
65#ifndef HAVE_ARCH_BUG
66#define BUG()
67#endif
68
Matt Mackallc8538a72005-05-01 08:59:01 -070069#ifndef HAVE_ARCH_BUG_ON
70#define BUG_ON(condition) do { if (condition) ; } while(0)
71#endif
72
73#ifndef HAVE_ARCH_WARN_ON
Ralf Baechle8c7c7c92006-10-19 23:28:34 -070074#define WARN_ON(condition) ({ \
Linus Torvalds8d4fbcf2007-07-31 21:12:07 -070075 int __ret_warn_on = !!(condition); \
Ralf Baechle8c7c7c92006-10-19 23:28:34 -070076 unlikely(__ret_warn_on); \
77})
Matt Mackallc8538a72005-05-01 08:59:01 -070078#endif
Arjan van de Vena8f18b92008-07-25 01:45:53 -070079
80#ifndef WARN
81#define WARN(condition, format...) ({ \
82 int __ret_warn_on = !!(condition); \
83 unlikely(__ret_warn_on); \
84})
85#endif
86
Matt Mackallc8538a72005-05-01 08:59:01 -070087#endif
88
Andrew Mortond69a8922006-10-06 00:43:49 -070089#define WARN_ON_ONCE(condition) ({ \
90 static int __warned; \
Linus Torvalds8d4fbcf2007-07-31 21:12:07 -070091 int __ret_warn_once = !!(condition); \
Andrew Mortond69a8922006-10-06 00:43:49 -070092 \
93 if (unlikely(__ret_warn_once)) \
94 if (WARN_ON(!__warned)) \
95 __warned = 1; \
96 unlikely(__ret_warn_once); \
Ingo Molnar74bb6a02006-06-25 05:48:09 -070097})
98
Arjan van de Ven45e9c0d2008-09-15 16:43:18 -070099#define WARN_ONCE(condition, format...) ({ \
100 static int __warned; \
101 int __ret_warn_once = !!(condition); \
102 \
103 if (unlikely(__ret_warn_once)) \
104 if (WARN(!__warned, format)) \
105 __warned = 1; \
106 unlikely(__ret_warn_once); \
107})
108
Dave Young717115e2008-07-25 01:45:58 -0700109#define WARN_ON_RATELIMIT(condition, state) \
110 WARN_ON((condition) && __ratelimit(state))
111
Ingo Molnar8eb94f82006-06-27 02:54:50 -0700112#ifdef CONFIG_SMP
113# define WARN_ON_SMP(x) WARN_ON(x)
114#else
115# define WARN_ON_SMP(x) do { } while (0)
116#endif
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#endif