at v4.13-rc4 1.8 kB view raw
1#ifndef _LINUX_BUG_H 2#define _LINUX_BUG_H 3 4#include <asm/bug.h> 5#include <linux/compiler.h> 6#include <linux/build_bug.h> 7 8enum bug_trap_type { 9 BUG_TRAP_TYPE_NONE = 0, 10 BUG_TRAP_TYPE_WARN = 1, 11 BUG_TRAP_TYPE_BUG = 2, 12}; 13 14struct pt_regs; 15 16#ifdef __CHECKER__ 17#define MAYBE_BUILD_BUG_ON(cond) (0) 18#else /* __CHECKER__ */ 19 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 28#endif /* __CHECKER__ */ 29 30#ifdef CONFIG_GENERIC_BUG 31#include <asm-generic/bug.h> 32 33static inline int is_warning_bug(const struct bug_entry *bug) 34{ 35 return bug->flags & BUGFLAG_WARNING; 36} 37 38struct bug_entry *find_bug(unsigned long bugaddr); 39 40enum bug_trap_type report_bug(unsigned long bug_addr, struct pt_regs *regs); 41 42/* These are defined by the architecture */ 43int is_valid_bugaddr(unsigned long addr); 44 45#else /* !CONFIG_GENERIC_BUG */ 46 47static inline enum bug_trap_type report_bug(unsigned long bug_addr, 48 struct pt_regs *regs) 49{ 50 return BUG_TRAP_TYPE_BUG; 51} 52 53#endif /* CONFIG_GENERIC_BUG */ 54 55/* 56 * Since detected data corruption should stop operation on the affected 57 * structures. Return value must be checked and sanely acted on by caller. 58 */ 59static inline __must_check bool check_data_corruption(bool v) { return v; } 60#define CHECK_DATA_CORRUPTION(condition, fmt, ...) \ 61 check_data_corruption(({ \ 62 bool corruption = unlikely(condition); \ 63 if (corruption) { \ 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__); \ 69 } \ 70 corruption; \ 71 })) 72 73#endif /* _LINUX_BUG_H */