Masahiro Yamada | 84b8bf6 | 2016-01-24 23:27:48 +0900 | [diff] [blame] | 1 | #ifndef _LINUX_BUG_H |
| 2 | #define _LINUX_BUG_H |
| 3 | |
Masahiro Yamada | 0a70fb4 | 2017-09-16 14:10:45 +0900 | [diff] [blame] | 4 | #include <vsprintf.h> /* for panic() */ |
Masahiro Yamada | 059a480 | 2017-09-16 14:10:44 +0900 | [diff] [blame] | 5 | #include <linux/build_bug.h> |
Masahiro Yamada | 0a70fb4 | 2017-09-16 14:10:45 +0900 | [diff] [blame] | 6 | #include <linux/compiler.h> |
| 7 | #include <linux/printk.h> |
| 8 | |
| 9 | #define BUG() do { \ |
| 10 | printk("BUG at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \ |
| 11 | panic("BUG!"); \ |
| 12 | } while (0) |
| 13 | |
| 14 | #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0) |
| 15 | |
| 16 | #define WARN_ON(condition) ({ \ |
| 17 | int __ret_warn_on = !!(condition); \ |
| 18 | if (unlikely(__ret_warn_on)) \ |
| 19 | printk("WARNING at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \ |
| 20 | unlikely(__ret_warn_on); \ |
| 21 | }) |
| 22 | |
Ramon Fried | 948f32c | 2018-06-06 00:38:59 +0300 | [diff] [blame^] | 23 | #define WARN(condition, format...) ({ \ |
| 24 | int __ret_warn_on = !!(condition); \ |
| 25 | if (unlikely(__ret_warn_on)) \ |
| 26 | printf(format); \ |
| 27 | unlikely(__ret_warn_on); \ |
| 28 | }) |
| 29 | |
Masahiro Yamada | 0a70fb4 | 2017-09-16 14:10:45 +0900 | [diff] [blame] | 30 | #define WARN_ON_ONCE(condition) ({ \ |
| 31 | static bool __warned; \ |
| 32 | int __ret_warn_once = !!(condition); \ |
| 33 | \ |
| 34 | if (unlikely(__ret_warn_once && !__warned)) { \ |
| 35 | __warned = true; \ |
| 36 | WARN_ON(1); \ |
| 37 | } \ |
| 38 | unlikely(__ret_warn_once); \ |
| 39 | }) |
Masahiro Yamada | 84b8bf6 | 2016-01-24 23:27:48 +0900 | [diff] [blame] | 40 | |
Ramon Fried | 948f32c | 2018-06-06 00:38:59 +0300 | [diff] [blame^] | 41 | #define WARN_ONCE(condition, format...) ({ \ |
| 42 | static bool __warned; \ |
| 43 | int __ret_warn_once = !!(condition); \ |
| 44 | \ |
| 45 | if (unlikely(__ret_warn_once && !__warned)) { \ |
| 46 | __warned = true; \ |
| 47 | WARN(1, format); \ |
| 48 | } \ |
| 49 | unlikely(__ret_warn_once); \ |
| 50 | }) |
| 51 | |
Masahiro Yamada | 84b8bf6 | 2016-01-24 23:27:48 +0900 | [diff] [blame] | 52 | #endif /* _LINUX_BUG_H */ |