Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _ASM_GENERIC_BUG_H |
| 2 | #define _ASM_GENERIC_BUG_H |
| 3 | |
| 4 | #include <linux/compiler.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | |
Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 6 | #ifdef CONFIG_BUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #ifndef HAVE_ARCH_BUG |
| 8 | #define BUG() do { \ |
Ingo Molnar | 91368d7 | 2006-03-23 03:00:54 -0800 | [diff] [blame] | 9 | printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | panic("BUG!"); \ |
| 11 | } while (0) |
| 12 | #endif |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #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 Xu | 684f978 | 2006-09-29 01:59:06 -0700 | [diff] [blame^] | 19 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #endif |
| 29 | |
Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 30 | #else /* !CONFIG_BUG */ |
| 31 | #ifndef HAVE_ARCH_BUG |
| 32 | #define BUG() |
| 33 | #endif |
| 34 | |
Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 35 | #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 Xu | 684f978 | 2006-09-29 01:59:06 -0700 | [diff] [blame^] | 40 | #define WARN_ON(condition) unlikely((condition)) |
Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 41 | #endif |
| 42 | #endif |
| 43 | |
Herbert Xu | 684f978 | 2006-09-29 01:59:06 -0700 | [diff] [blame^] | 44 | #define WARN_ON_ONCE(condition) ({ \ |
Ingo Molnar | 74bb6a0 | 2006-06-25 05:48:09 -0700 | [diff] [blame] | 45 | static int __warn_once = 1; \ |
Herbert Xu | 684f978 | 2006-09-29 01:59:06 -0700 | [diff] [blame^] | 46 | typeof(condition) __ret_warn_once = (condition);\ |
Ingo Molnar | 74bb6a0 | 2006-06-25 05:48:09 -0700 | [diff] [blame] | 47 | \ |
Herbert Xu | 684f978 | 2006-09-29 01:59:06 -0700 | [diff] [blame^] | 48 | if (likely(__warn_once)) \ |
| 49 | if (WARN_ON(__ret_warn_once)) \ |
| 50 | __warn_once = 0; \ |
| 51 | unlikely(__ret_warn_once); \ |
Ingo Molnar | 74bb6a0 | 2006-06-25 05:48:09 -0700 | [diff] [blame] | 52 | }) |
| 53 | |
Ingo Molnar | 8eb94f8 | 2006-06-27 02:54:50 -0700 | [diff] [blame] | 54 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #endif |