summaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2024-01-03 11:19:48 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2024-01-11 16:16:58 +0100
commit3b437626ed4777d8ef6de28bf282bbbb36bee69f (patch)
treee9068f3492e51947ec2039ce103f630da2bf5da0 /include/linux
parent89f1040d09f2fb4da2a2e056e320662a5b87671d (diff)
downloadbarebox-3b437626ed4777d8ef6de28bf282bbbb36bee69f.tar.gz
barebox-3b437626ed4777d8ef6de28bf282bbbb36bee69f.tar.xz
lib: add optional linked list debugging
When enabled, this outputs messages like: list_del corruption, 000000005fe4a9d0->next is LIST_POISON1 (0000000000000100) which can be useful when debugging. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240103101948.2630473-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/bug.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/linux/bug.h b/include/linux/bug.h
index d8fc328a07..8ea5f8d1b2 100644
--- a/include/linux/bug.h
+++ b/include/linux/bug.h
@@ -6,4 +6,21 @@
#include <asm-generic/bug.h>
#include <linux/build_bug.h>
+/*
+ * 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)) { \
+ panic(fmt, ##__VA_ARGS__); \
+ } else \
+ WARN(1, fmt, ##__VA_ARGS__); \
+ } \
+ corruption; \
+ }))
+
#endif /* _LINUX_BUG_H */