]>
Commit | Line | Data |
---|---|---|
7664c5a1 JF |
1 | #ifndef _LINUX_BUG_H |
2 | #define _LINUX_BUG_H | |
3 | ||
7664c5a1 | 4 | #include <asm/bug.h> |
a3ccc497 | 5 | #include <linux/compiler.h> |
bc6245e5 | 6 | #include <linux/build_bug.h> |
7664c5a1 JF |
7 | |
8 | enum bug_trap_type { | |
9 | BUG_TRAP_TYPE_NONE = 0, | |
10 | BUG_TRAP_TYPE_WARN = 1, | |
11 | BUG_TRAP_TYPE_BUG = 2, | |
12 | }; | |
13 | ||
608e2619 HC |
14 | struct pt_regs; |
15 | ||
35edd910 | 16 | #ifdef __CHECKER__ |
ff20c2e0 | 17 | #define MAYBE_BUILD_BUG_ON(cond) (0) |
35edd910 PG |
18 | #else /* __CHECKER__ */ |
19 | ||
ff20c2e0 KS |
20 | #define MAYBE_BUILD_BUG_ON(cond) \ |
21 | do { \ | |
22 | if (__builtin_constant_p((cond))) \ | |
23 | BUILD_BUG_ON(cond); \ | |
24 | else \ | |
25 | BUG_ON(cond); \ | |
26 | } while (0) | |
27 | ||
35edd910 PG |
28 | #endif /* __CHECKER__ */ |
29 | ||
7664c5a1 JF |
30 | #ifdef CONFIG_GENERIC_BUG |
31 | #include <asm-generic/bug.h> | |
32 | ||
33 | static inline int is_warning_bug(const struct bug_entry *bug) | |
34 | { | |
35 | return bug->flags & BUGFLAG_WARNING; | |
36 | } | |
37 | ||
19d43626 | 38 | struct bug_entry *find_bug(unsigned long bugaddr); |
7664c5a1 | 39 | |
608e2619 | 40 | enum bug_trap_type report_bug(unsigned long bug_addr, struct pt_regs *regs); |
7664c5a1 | 41 | |
7664c5a1 JF |
42 | /* These are defined by the architecture */ |
43 | int is_valid_bugaddr(unsigned long addr); | |
44 | ||
45 | #else /* !CONFIG_GENERIC_BUG */ | |
46 | ||
608e2619 HC |
47 | static inline enum bug_trap_type report_bug(unsigned long bug_addr, |
48 | struct pt_regs *regs) | |
7664c5a1 JF |
49 | { |
50 | return BUG_TRAP_TYPE_BUG; | |
51 | } | |
7664c5a1 JF |
52 | |
53 | #endif /* CONFIG_GENERIC_BUG */ | |
de54ebbe KC |
54 | |
55 | /* | |
56 | * Since detected data corruption should stop operation on the affected | |
85caa95b | 57 | * structures. Return value must be checked and sanely acted on by caller. |
de54ebbe | 58 | */ |
85caa95b | 59 | static inline __must_check bool check_data_corruption(bool v) { return v; } |
de54ebbe | 60 | #define CHECK_DATA_CORRUPTION(condition, fmt, ...) \ |
85caa95b KC |
61 | check_data_corruption(({ \ |
62 | bool corruption = unlikely(condition); \ | |
63 | if (corruption) { \ | |
de54ebbe KC |
64 | if (IS_ENABLED(CONFIG_BUG_ON_DATA_CORRUPTION)) { \ |
65 | pr_err(fmt, ##__VA_ARGS__); \ | |
66 | BUG(); \ | |
67 | } else \ | |
68 | WARN(1, fmt, ##__VA_ARGS__); \ | |
de54ebbe | 69 | } \ |
85caa95b KC |
70 | corruption; \ |
71 | })) | |
de54ebbe | 72 | |
7664c5a1 | 73 | #endif /* _LINUX_BUG_H */ |