Commit 0a70fb4c1c180d6ad6cd4c1dcd3fae8c5d4dd62e

Authored by Masahiro Yamada
Committed by Tom Rini
1 parent 059a48096c

bug.h: move runtime BUG/WARN macros into <linux/bug.h>

Collect runtime BUG/WARN into a self-contained header <linux/bug.h>
to make these macros easier to use.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

Showing 4 changed files with 29 additions and 24 deletions Side-by-side Diff

drivers/usb/dwc3/linux-compat.h
... ... @@ -14,7 +14,6 @@
14 14  
15 15 #define WARN(val, format, arg...) debug(format, ##arg)
16 16 #define dev_WARN(dev, format, arg...) debug(format, ##arg)
17   -#define WARN_ON_ONCE(val) debug("Error %d\n", val)
18 17  
19 18 static inline size_t strlcat(char *dest, const char *src, size_t n)
20 19 {
... ... @@ -23,6 +23,7 @@
23 23 #include <time.h>
24 24 #include <asm-offsets.h>
25 25 #include <linux/bitops.h>
  26 +#include <linux/bug.h>
26 27 #include <linux/delay.h>
27 28 #include <linux/types.h>
28 29 #include <linux/printk.h>
... ... @@ -89,14 +90,6 @@
89 90 #define assert(x) \
90 91 ({ if (!(x) && _DEBUG) \
91 92 __assert_fail(#x, __FILE__, __LINE__, __func__); })
92   -
93   -#ifndef BUG
94   -#define BUG() do { \
95   - printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
96   - panic("BUG!"); \
97   -} while (0)
98   -#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
99   -#endif /* BUG */
100 93  
101 94 typedef void (interrupt_handler_t)(void *);
102 95  
1 1 #ifndef _LINUX_BUG_H
2 2 #define _LINUX_BUG_H
3 3  
  4 +#include <vsprintf.h> /* for panic() */
4 5 #include <linux/build_bug.h>
  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 +
  23 +#define WARN_ON_ONCE(condition) ({ \
  24 + static bool __warned; \
  25 + int __ret_warn_once = !!(condition); \
  26 + \
  27 + if (unlikely(__ret_warn_once && !__warned)) { \
  28 + __warned = true; \
  29 + WARN_ON(1); \
  30 + } \
  31 + unlikely(__ret_warn_once); \
  32 +})
5 33  
6 34 #endif /* _LINUX_BUG_H */
include/linux/compat.h
... ... @@ -87,21 +87,6 @@
87 87  
88 88 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
89 89  
90   -#ifndef BUG
91   -#define BUG() do { \
92   - printf("U-Boot BUG at %s:%d!\n", __FILE__, __LINE__); \
93   -} while (0)
94   -
95   -#define BUG_ON(condition) do { if (condition) BUG(); } while(0)
96   -#endif /* BUG */
97   -
98   -#define WARN_ON(condition) ({ \
99   - int __ret_warn_on = !!(condition); \
100   - if (unlikely(__ret_warn_on)) \
101   - printf("WARNING in %s line %d\n", __FILE__, __LINE__); \
102   - unlikely(__ret_warn_on); \
103   -})
104   -
105 90 #define PAGE_SIZE 4096
106 91  
107 92 /* drivers/char/random.c */