blob: c92ae0f166ff44f1757f456a132202b22f0f5368 [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
Ralf Baechle8c7c7c92006-10-19 23:28:34 -070040#define WARN_ON(condition) ({ \
41 typeof(condition) __ret_warn_on = (condition); \
42 unlikely(__ret_warn_on); \
43})
Matt Mackallc8538a72005-05-01 08:59:01 -070044#endif
45#endif
46
Andrew Mortond69a8922006-10-06 00:43:49 -070047#define WARN_ON_ONCE(condition) ({ \
48 static int __warned; \
49 typeof(condition) __ret_warn_once = (condition); \
50 \
51 if (unlikely(__ret_warn_once)) \
52 if (WARN_ON(!__warned)) \
53 __warned = 1; \
54 unlikely(__ret_warn_once); \
Ingo Molnar74bb6a02006-06-25 05:48:09 -070055})
56
Ingo Molnar8eb94f82006-06-27 02:54:50 -070057#ifdef CONFIG_SMP
58# define WARN_ON_SMP(x) WARN_ON(x)
59#else
60# define WARN_ON_SMP(x) do { } while (0)
61#endif
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#endif