blob: a5250895155ef6e5affcae708a4a79f692f037e2 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#ifndef HAVE_ARCH_BUG
8#define BUG() do { \
Ingo Molnar91368d72006-03-23 03:00:54 -08009 printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 panic("BUG!"); \
11} while (0)
12#endif
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#ifndef HAVE_ARCH_BUG_ON
15#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
16#endif
17
18#ifndef HAVE_ARCH_WARN_ON
Herbert Xu684f9782006-09-29 01:59:06 -070019#define WARN_ON(condition) ({ \
20 typeof(condition) __ret_warn_on = (condition); \
21 if (unlikely(__ret_warn_on)) { \
22 printk("BUG: warning at %s:%d/%s()\n", __FILE__, \
23 __LINE__, __FUNCTION__); \
24 dump_stack(); \
25 } \
26 unlikely(__ret_warn_on); \
27})
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#endif
29
Matt Mackallc8538a72005-05-01 08:59:01 -070030#else /* !CONFIG_BUG */
31#ifndef HAVE_ARCH_BUG
32#define BUG()
33#endif
34
Matt Mackallc8538a72005-05-01 08:59:01 -070035#ifndef HAVE_ARCH_BUG_ON
36#define BUG_ON(condition) do { if (condition) ; } while(0)
37#endif
38
39#ifndef HAVE_ARCH_WARN_ON
Herbert Xu684f9782006-09-29 01:59:06 -070040#define WARN_ON(condition) unlikely((condition))
Matt Mackallc8538a72005-05-01 08:59:01 -070041#endif
42#endif
43
Herbert Xu684f9782006-09-29 01:59:06 -070044#define WARN_ON_ONCE(condition) ({ \
Ingo Molnar74bb6a02006-06-25 05:48:09 -070045 static int __warn_once = 1; \
Herbert Xu684f9782006-09-29 01:59:06 -070046 typeof(condition) __ret_warn_once = (condition);\
Ingo Molnar74bb6a02006-06-25 05:48:09 -070047 \
Herbert Xu684f9782006-09-29 01:59:06 -070048 if (likely(__warn_once)) \
49 if (WARN_ON(__ret_warn_once)) \
50 __warn_once = 0; \
51 unlikely(__ret_warn_once); \
Ingo Molnar74bb6a02006-06-25 05:48:09 -070052})
53
Ingo Molnar8eb94f82006-06-27 02:54:50 -070054#ifdef CONFIG_SMP
55# define WARN_ON_SMP(x) WARN_ON(x)
56#else
57# define WARN_ON_SMP(x) do { } while (0)
58#endif
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#endif