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