Rev 5056 | Rev 6082 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5056 | Rev 5270 | ||
---|---|---|---|
1 | #ifndef _ASM_GENERIC_BUG_H |
1 | #ifndef _ASM_GENERIC_BUG_H |
2 | #define _ASM_GENERIC_BUG_H |
2 | #define _ASM_GENERIC_BUG_H |
3 | - | ||
4 | //extern __printf(3, 4) |
- | |
5 | //void warn_slowpath_fmt(const char *file, const int line, |
- | |
6 | // const char *fmt, ...); |
3 | |
7 | //extern __printf(4, 5) |
- | |
8 | //void warn_slowpath_fmt_taint(const char *file, const int line, unsigned taint, |
- | |
9 | // const char *fmt, ...); |
- | |
10 | - | ||
11 | //extern void warn_slowpath_null(const char *file, const int line); |
4 | #include |
12 | 5 | ||
13 | #define __WARN() printf("\nWARNING: at %s:%d\n", __FILE__, __LINE__) |
6 | #define __WARN() printf("\nWARNING: at %s:%d\n", __FILE__, __LINE__) |
14 | //#define __WARN_printf(arg...) printf("\nWARNING: at %s:%d\n", __FILE__, __LINE__) |
7 | //#define __WARN_printf(arg...) printf("\nWARNING: at %s:%d\n", __FILE__, __LINE__) |
15 | #define __WARN_printf(arg...) do { printf(arg); __WARN(); } while (0) |
8 | #define __WARN_printf(arg...) do { printf(arg); __WARN(); } while (0) |
16 | 9 | ||
17 | #define WARN(condition, format...) ({ \ |
10 | #define WARN(condition, format...) ({ \ |
18 | int __ret_warn_on = !!(condition); \ |
11 | int __ret_warn_on = !!(condition); \ |
19 | if (unlikely(__ret_warn_on)) \ |
12 | if (unlikely(__ret_warn_on)) \ |
20 | __WARN_printf(format); \ |
13 | __WARN_printf(format); \ |
21 | unlikely(__ret_warn_on); \ |
14 | unlikely(__ret_warn_on); \ |
22 | }) |
15 | }) |
23 | 16 | ||
24 | 17 | ||
25 | #define WARN_ON(condition) ({ \ |
18 | #define WARN_ON(condition) ({ \ |
26 | int __ret_warn_on = !!(condition); \ |
19 | int __ret_warn_on = !!(condition); \ |
27 | if (unlikely(__ret_warn_on)) \ |
20 | if (unlikely(__ret_warn_on)) \ |
28 | __WARN(); \ |
21 | __WARN(); \ |
29 | unlikely(__ret_warn_on); \ |
22 | unlikely(__ret_warn_on); \ |
30 | }) |
23 | }) |
31 | 24 | ||
32 | 25 | ||
33 | #define WARN_ONCE(condition, format...) ({ \ |
26 | #define WARN_ONCE(condition, format...) ({ \ |
34 | static bool __warned; \ |
27 | static bool __warned; \ |
35 | int __ret_warn_once = !!(condition); \ |
28 | int __ret_warn_once = !!(condition); \ |
36 | \ |
29 | \ |
37 | if (unlikely(__ret_warn_once)) \ |
30 | if (unlikely(__ret_warn_once)) \ |
38 | if (WARN(!__warned, format)) \ |
31 | if (WARN(!__warned, format)) \ |
39 | __warned = true; \ |
32 | __warned = true; \ |
40 | unlikely(__ret_warn_once); \ |
33 | unlikely(__ret_warn_once); \ |
41 | }) |
34 | }) |
42 | 35 | ||
43 | 36 | ||
44 | #define WARN_ON_ONCE(condition) ({ \ |
37 | #define WARN_ON_ONCE(condition) ({ \ |
45 | static bool __warned; \ |
38 | static bool __warned; \ |
46 | int __ret_warn_once = !!(condition); \ |
39 | int __ret_warn_once = !!(condition); \ |
47 | \ |
40 | \ |
48 | if (unlikely(__ret_warn_once)) \ |
41 | if (unlikely(__ret_warn_once)) \ |
49 | if (WARN_ON(!__warned)) \ |
42 | if (WARN_ON(!__warned)) \ |
50 | __warned = true; \ |
43 | __warned = true; \ |
51 | unlikely(__ret_warn_once); \ |
44 | unlikely(__ret_warn_once); \ |
52 | }) |
45 | }) |
53 | 46 | ||
54 | #define BUG() do { \ |
47 | #define BUG() do { \ |
55 | printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \ |
48 | printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \ |
56 | } while (0) |
49 | } while (0) |
57 | 50 | ||
58 | #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0) |
51 | #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0) |
59 | 52 | ||
60 | /* Force a compilation error if a constant expression is not a power of 2 */ |
53 | /* Force a compilation error if a constant expression is not a power of 2 */ |
61 | #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ |
54 | #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ |
62 | BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) |
55 | BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) |
- | 56 | ||
- | 57 | /* Force a compilation error if condition is true, but also produce a |
|
- | 58 | result (of value 0 and type size_t), so the expression can be used |
|
- | 59 | e.g. in a structure initializer (or where-ever else comma expressions |
|
- | 60 | aren't permitted). */ |
|
- | 61 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) |
|
- | 62 | #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) |
|
- | 63 | ||
- | 64 | /* |
|
- | 65 | * BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the |
|
- | 66 | * expression but avoids the generation of any code, even if that expression |
|
- | 67 | * has side-effects. |
|
- | 68 | */ |
|
- | 69 | #define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e)))) |
|
- | 70 | ||
- | 71 | /** |
|
- | 72 | * BUILD_BUG_ON_MSG - break compile if a condition is true & emit supplied |
|
- | 73 | * error message. |
|
- | 74 | * @condition: the condition which the compiler should know is false. |
|
- | 75 | * |
|
- | 76 | * See BUILD_BUG_ON for description. |
|
- | 77 | */ |
|
- | 78 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) |
|
- | 79 | ||
- | 80 | /** |
|
- | 81 | * BUILD_BUG_ON - break compile if a condition is true. |
|
- | 82 | * @condition: the condition which the compiler should know is false. |
|
- | 83 | * |
|
- | 84 | * If you have some code which relies on certain constants being equal, or |
|
- | 85 | * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to |
|
- | 86 | * detect if someone changes it. |
|
- | 87 | * |
|
- | 88 | * The implementation uses gcc's reluctance to create a negative array, but gcc |
|
- | 89 | * (as of 4.4) only emits that error for obvious cases (e.g. not arguments to |
|
- | 90 | * inline functions). Luckily, in 4.3 they added the "error" function |
|
- | 91 | * attribute just for this type of case. Thus, we use a negative sized array |
|
- | 92 | * (should always create an error on gcc versions older than 4.4) and then call |
|
- | 93 | * an undefined function with the error attribute (should always create an |
|
- | 94 | * error on gcc 4.3 and later). If for some reason, neither creates a |
|
- | 95 | * compile-time error, we'll still have a link-time error, which is harder to |
|
- | 96 | * track down. |
|
- | 97 | */ |
|
- | 98 | #ifndef __OPTIMIZE__ |
|
- | 99 | #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) |
|
- | 100 | #else |
|
- | 101 | #define BUILD_BUG_ON(condition) \ |
|
- | 102 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) |
|
- | 103 | #endif |
|
- | 104 | ||
- | 105 | /** |
|
- | 106 | * BUILD_BUG - break compile if used. |
|
- | 107 | * |
|
- | 108 | * If you have some code that you expect the compiler to eliminate at |
|
- | 109 | * build time, you should use BUILD_BUG to detect if it is |
|
- | 110 | * unexpectedly used. |
|
- | 111 | */ |
|
- | 112 | #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed") |
|
63 | - | ||
64 | - | ||
65 | #define printk_once(fmt, ...) \ |
- | |
66 | ({ \ |
- | |
67 | static bool __print_once; \ |
- | |
68 | \ |
- | |
69 | if (!__print_once) { \ |
- | |
70 | __print_once = true; \ |
- | |
71 | printk(fmt, ##__VA_ARGS__); \ |
- | |
72 | } \ |
113 | |
73 | }) |
114 | |
74 | 115 | ||
75 | 116 | ||
76 | #define pr_warn_once(fmt, ...) \ |
117 | #define pr_warn_once(fmt, ...) \ |
77 | printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
118 | printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
78 | 119 | ||
79 | #endif |
120 | #endif |