[PATCH 18/20] Add WARN_ONCE() macro
Sascha Hauer
s.hauer at pengutronix.de
Thu Aug 13 09:42:55 EDT 2020
This adds WARN_ONCE from the Linux Kernel. It is useful to warn only
once when we would otherwise spam the log.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
include/asm-generic/bug.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 8583d2425f..82b78261fc 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -34,4 +34,17 @@
unlikely(__ret_warn_on); \
})
#endif
+
+#define WARN_ONCE(condition, format...) ({ \
+ static int __warned; \
+ int __ret_warn_once = !!(condition); \
+ \
+ if (unlikely(__ret_warn_once)) { \
+ if (WARN(!__warned, format)) { \
+ __warned = 1; \
+ dump_stack(); \
+ } \
+ } \
+ unlikely(__ret_warn_once); \
+})
#endif
--
2.28.0
More information about the barebox
mailing list