]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef _ASM_GENERIC_BUG_H |
3 | #define _ASM_GENERIC_BUG_H | |
4 | ||
5 | #include <linux/compiler.h> | |
1da177e4 | 6 | |
09682c1d PM |
7 | #ifdef CONFIG_GENERIC_BUG |
8 | #define BUGFLAG_WARNING (1 << 0) | |
19d43626 PZ |
9 | #define BUGFLAG_ONCE (1 << 1) |
10 | #define BUGFLAG_DONE (1 << 2) | |
f26dee15 | 11 | #define BUGFLAG_TAINT(taint) ((taint) << 8) |
09682c1d PM |
12 | #define BUG_GET_TAINT(bug) ((bug)->flags >> 8) |
13 | #endif | |
14 | ||
15 | #ifndef __ASSEMBLY__ | |
16 | #include <linux/kernel.h> | |
17 | ||
c8538a7a | 18 | #ifdef CONFIG_BUG |
7664c5a1 JF |
19 | |
20 | #ifdef CONFIG_GENERIC_BUG | |
7664c5a1 | 21 | struct bug_entry { |
b93a531e | 22 | #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS |
7664c5a1 | 23 | unsigned long bug_addr; |
b93a531e JB |
24 | #else |
25 | signed int bug_addr_disp; | |
26 | #endif | |
7664c5a1 | 27 | #ifdef CONFIG_DEBUG_BUGVERBOSE |
b93a531e | 28 | #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS |
7664c5a1 | 29 | const char *file; |
b93a531e JB |
30 | #else |
31 | signed int file_disp; | |
32 | #endif | |
7664c5a1 JF |
33 | unsigned short line; |
34 | #endif | |
35 | unsigned short flags; | |
36 | }; | |
7664c5a1 JF |
37 | #endif /* CONFIG_GENERIC_BUG */ |
38 | ||
af9379c7 DB |
39 | /* |
40 | * Don't use BUG() or BUG_ON() unless there's really no way out; one | |
41 | * example might be detecting data structure corruption in the middle | |
42 | * of an operation that can't be backed out of. If the (sub)system | |
43 | * can somehow continue operating, perhaps with reduced functionality, | |
44 | * it's probably not BUG-worthy. | |
45 | * | |
46 | * If you're tempted to BUG(), think again: is completely giving up | |
47 | * really the *only* solution? There are usually better options, where | |
48 | * users don't need to reboot ASAP and can mostly shut down cleanly. | |
49 | */ | |
1da177e4 LT |
50 | #ifndef HAVE_ARCH_BUG |
51 | #define BUG() do { \ | |
d5c003b4 | 52 | printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \ |
1da177e4 LT |
53 | panic("BUG!"); \ |
54 | } while (0) | |
55 | #endif | |
56 | ||
1da177e4 | 57 | #ifndef HAVE_ARCH_BUG_ON |
a3f7607d | 58 | #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0) |
1da177e4 LT |
59 | #endif |
60 | ||
19d43626 PZ |
61 | #ifdef __WARN_FLAGS |
62 | #define __WARN_TAINT(taint) __WARN_FLAGS(BUGFLAG_TAINT(taint)) | |
63 | #define __WARN_ONCE_TAINT(taint) __WARN_FLAGS(BUGFLAG_ONCE|BUGFLAG_TAINT(taint)) | |
64 | ||
65 | #define WARN_ON_ONCE(condition) ({ \ | |
66 | int __ret_warn_on = !!(condition); \ | |
67 | if (unlikely(__ret_warn_on)) \ | |
68 | __WARN_ONCE_TAINT(TAINT_WARN); \ | |
69 | unlikely(__ret_warn_on); \ | |
70 | }) | |
71 | #endif | |
72 | ||
af9379c7 DB |
73 | /* |
74 | * WARN(), WARN_ON(), WARN_ON_ONCE, and so on can be used to report | |
75 | * significant issues that need prompt attention if they should ever | |
76 | * appear at runtime. Use the versions with printk format strings | |
77 | * to provide better diagnostics. | |
78 | */ | |
b2be0527 | 79 | #ifndef __WARN_TAINT |
b9075fa9 JP |
80 | extern __printf(3, 4) |
81 | void warn_slowpath_fmt(const char *file, const int line, | |
82 | const char *fmt, ...); | |
83 | extern __printf(4, 5) | |
84 | void warn_slowpath_fmt_taint(const char *file, const int line, unsigned taint, | |
85 | const char *fmt, ...); | |
57adc4d2 | 86 | extern void warn_slowpath_null(const char *file, const int line); |
79b4cc5e | 87 | #define WANT_WARN_ON_SLOWPATH |
57adc4d2 AK |
88 | #define __WARN() warn_slowpath_null(__FILE__, __LINE__) |
89 | #define __WARN_printf(arg...) warn_slowpath_fmt(__FILE__, __LINE__, arg) | |
b2be0527 BH |
90 | #define __WARN_printf_taint(taint, arg...) \ |
91 | warn_slowpath_fmt_taint(__FILE__, __LINE__, taint, arg) | |
a8f18b90 | 92 | #else |
b2be0527 | 93 | #define __WARN() __WARN_TAINT(TAINT_WARN) |
ec5679e5 | 94 | #define __WARN_printf(arg...) do { printk(arg); __WARN(); } while (0) |
b2be0527 BH |
95 | #define __WARN_printf_taint(taint, arg...) \ |
96 | do { printk(arg); __WARN_TAINT(taint); } while (0) | |
3a6a62f9 OJ |
97 | #endif |
98 | ||
2553b67a JP |
99 | /* used internally by panic.c */ |
100 | struct warn_args; | |
0b396923 | 101 | struct pt_regs; |
2553b67a JP |
102 | |
103 | void __warn(const char *file, int line, void *caller, unsigned taint, | |
104 | struct pt_regs *regs, struct warn_args *args); | |
105 | ||
3a6a62f9 | 106 | #ifndef WARN_ON |
684f9783 | 107 | #define WARN_ON(condition) ({ \ |
8d4fbcfb | 108 | int __ret_warn_on = !!(condition); \ |
3a6a62f9 OJ |
109 | if (unlikely(__ret_warn_on)) \ |
110 | __WARN(); \ | |
684f9783 HX |
111 | unlikely(__ret_warn_on); \ |
112 | }) | |
1da177e4 LT |
113 | #endif |
114 | ||
a8f18b90 | 115 | #ifndef WARN |
19d43626 | 116 | #define WARN(condition, format...) ({ \ |
a8f18b90 AV |
117 | int __ret_warn_on = !!(condition); \ |
118 | if (unlikely(__ret_warn_on)) \ | |
119 | __WARN_printf(format); \ | |
120 | unlikely(__ret_warn_on); \ | |
121 | }) | |
122 | #endif | |
123 | ||
b2be0527 BH |
124 | #define WARN_TAINT(condition, taint, format...) ({ \ |
125 | int __ret_warn_on = !!(condition); \ | |
126 | if (unlikely(__ret_warn_on)) \ | |
127 | __WARN_printf_taint(taint, format); \ | |
128 | unlikely(__ret_warn_on); \ | |
129 | }) | |
130 | ||
19d43626 | 131 | #ifndef WARN_ON_ONCE |
d69a8922 | 132 | #define WARN_ON_ONCE(condition) ({ \ |
7ccaba53 | 133 | static bool __section(.data.unlikely) __warned; \ |
8d4fbcfb | 134 | int __ret_warn_once = !!(condition); \ |
d69a8922 | 135 | \ |
dfbf2897 SR |
136 | if (unlikely(__ret_warn_once && !__warned)) { \ |
137 | __warned = true; \ | |
138 | WARN_ON(1); \ | |
139 | } \ | |
d69a8922 | 140 | unlikely(__ret_warn_once); \ |
74bb6a09 | 141 | }) |
19d43626 | 142 | #endif |
74bb6a09 | 143 | |
45e9c0de | 144 | #define WARN_ONCE(condition, format...) ({ \ |
7ccaba53 | 145 | static bool __section(.data.unlikely) __warned; \ |
45e9c0de AV |
146 | int __ret_warn_once = !!(condition); \ |
147 | \ | |
dfbf2897 SR |
148 | if (unlikely(__ret_warn_once && !__warned)) { \ |
149 | __warned = true; \ | |
150 | WARN(1, format); \ | |
151 | } \ | |
45e9c0de AV |
152 | unlikely(__ret_warn_once); \ |
153 | }) | |
154 | ||
b2be0527 | 155 | #define WARN_TAINT_ONCE(condition, taint, format...) ({ \ |
7ccaba53 | 156 | static bool __section(.data.unlikely) __warned; \ |
b2be0527 BH |
157 | int __ret_warn_once = !!(condition); \ |
158 | \ | |
dfbf2897 SR |
159 | if (unlikely(__ret_warn_once && !__warned)) { \ |
160 | __warned = true; \ | |
161 | WARN_TAINT(1, taint, format); \ | |
162 | } \ | |
b2be0527 BH |
163 | unlikely(__ret_warn_once); \ |
164 | }) | |
165 | ||
b607e70e JT |
166 | #else /* !CONFIG_BUG */ |
167 | #ifndef HAVE_ARCH_BUG | |
a4b5d580 | 168 | #define BUG() do {} while (1) |
b607e70e JT |
169 | #endif |
170 | ||
171 | #ifndef HAVE_ARCH_BUG_ON | |
3c047057 | 172 | #define BUG_ON(condition) do { if (condition) BUG(); } while (0) |
b607e70e JT |
173 | #endif |
174 | ||
175 | #ifndef HAVE_ARCH_WARN_ON | |
176 | #define WARN_ON(condition) ({ \ | |
177 | int __ret_warn_on = !!(condition); \ | |
178 | unlikely(__ret_warn_on); \ | |
179 | }) | |
180 | #endif | |
181 | ||
182 | #ifndef WARN | |
183 | #define WARN(condition, format...) ({ \ | |
184 | int __ret_warn_on = !!(condition); \ | |
4e50ebde | 185 | no_printk(format); \ |
b607e70e JT |
186 | unlikely(__ret_warn_on); \ |
187 | }) | |
188 | #endif | |
189 | ||
190 | #define WARN_ON_ONCE(condition) WARN_ON(condition) | |
191 | #define WARN_ONCE(condition, format...) WARN(condition, format) | |
192 | #define WARN_TAINT(condition, taint, format...) WARN(condition, format) | |
193 | #define WARN_TAINT_ONCE(condition, taint, format...) WARN(condition, format) | |
194 | ||
195 | #endif | |
196 | ||
2092e6be SR |
197 | /* |
198 | * WARN_ON_SMP() is for cases that the warning is either | |
199 | * meaningless for !SMP or may even cause failures. | |
200 | * This is usually used for cases that we have | |
201 | * WARN_ON(!spin_is_locked(&lock)) checks, as spin_is_locked() | |
202 | * returns 0 for uniprocessor settings. | |
203 | * It can also be used with values that are only defined | |
204 | * on SMP: | |
205 | * | |
206 | * struct foo { | |
207 | * [...] | |
208 | * #ifdef CONFIG_SMP | |
209 | * int bar; | |
210 | * #endif | |
211 | * }; | |
212 | * | |
213 | * void func(struct foo *zoot) | |
214 | * { | |
215 | * WARN_ON_SMP(!zoot->bar); | |
216 | * | |
217 | * For CONFIG_SMP, WARN_ON_SMP() should act the same as WARN_ON(), | |
218 | * and should be a nop and return false for uniprocessor. | |
219 | * | |
220 | * if (WARN_ON_SMP(x)) returns true only when CONFIG_SMP is set | |
221 | * and x is true. | |
222 | */ | |
8eb94f80 IM |
223 | #ifdef CONFIG_SMP |
224 | # define WARN_ON_SMP(x) WARN_ON(x) | |
225 | #else | |
ccd0d44f SR |
226 | /* |
227 | * Use of ({0;}) because WARN_ON_SMP(x) may be used either as | |
228 | * a stand alone line statement or as a condition in an if () | |
229 | * statement. | |
230 | * A simple "0" would cause gcc to give a "statement has no effect" | |
231 | * warning. | |
232 | */ | |
2092e6be | 233 | # define WARN_ON_SMP(x) ({0;}) |
8eb94f80 IM |
234 | #endif |
235 | ||
2603efa3 PM |
236 | #endif /* __ASSEMBLY__ */ |
237 | ||
1da177e4 | 238 | #endif |