diff options
Diffstat (limited to 'include/linux/bug.h')
-rw-r--r-- | include/linux/bug.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/linux/bug.h b/include/linux/bug.h index 292d6a10b0c2..5828489309bb 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -121,4 +121,23 @@ static inline enum bug_trap_type report_bug(unsigned long bug_addr, } #endif /* CONFIG_GENERIC_BUG */ + +/* + * Since detected data corruption should stop operation on the affected + * structures. Return value must be checked and sanely acted on by caller. + */ +static inline __must_check bool check_data_corruption(bool v) { return v; } +#define CHECK_DATA_CORRUPTION(condition, fmt, ...) \ + check_data_corruption(({ \ + bool corruption = unlikely(condition); \ + if (corruption) { \ + if (IS_ENABLED(CONFIG_BUG_ON_DATA_CORRUPTION)) { \ + pr_err(fmt, ##__VA_ARGS__); \ + BUG(); \ + } else \ + WARN(1, fmt, ##__VA_ARGS__); \ + } \ + corruption; \ + })) + #endif /* _LINUX_BUG_H */ |