Skip to contentSkip to conversation

bug.h: introduce WARN_ONCE

PATCH Superseded Ramon Fried 1 participant 1 message Jun 5, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bug.h: introduce WARN_ONCE

Add WARN_ONCE definition to allow single time notification of warnings to the user.
Taken from Linux kernel (4.17) with slight changes (Removed __section(.data.once))

---
v2: removed change-id, added taken from description to commit message.

 include/linux/bug.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
include/linux/bug.h +18 -0
index f07bb716fc..67b6057a22 100644
@@ -20,6 +20,13 @@
 	unlikely(__ret_warn_on);					\
 })
 
+#define WARN(condition, format...) ({                   \
+	int __ret_warn_on = !!(condition);              \
+	if (unlikely(__ret_warn_on))                    \
+		__WARN_printf(format);                  \
+	unlikely(__ret_warn_on);                    \
+})
+
 #define WARN_ON_ONCE(condition)	({				\
 	static bool __warned;					\
 	int __ret_warn_once = !!(condition);			\
@@ -31,4 +38,15 @@
 	unlikely(__ret_warn_once);				\
 })
 
+#define WARN_ONCE(condition, format...) ({          \
+	static bool __warned;     \
+	int __ret_warn_once = !!(condition);            \
+								\
+	if (unlikely(__ret_warn_once && !__warned)) {       \
+		__warned = true;                \
+		WARN(1, format);                \
+	}                           \
+	unlikely(__ret_warn_once);              \
+})
+
 #endif	/* _LINUX_BUG_H */
Signature · 1 line
2.17.1