diff mbox series

[U-Boot,v3] bug.h: introduce WARN_ONCE

Message ID 20180605213859.18099-1-ramon.fried@gmail.com
State Accepted
Delegated to: Tom Rini
Headers show
Series [U-Boot,v3] bug.h: introduce WARN_ONCE | expand

Commit Message

Ramon Fried June 5, 2018, 9:38 p.m. UTC
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))

Signed-off-by: Ramon Fried <ramon.fried@gmail.com>
---
Facepalm, missed that it was actually a v3 and not a v2.

v2: accidently commited the wrong file. noticed by Masahiro Yamada
v3: removed change-id, added taken from description to commit message.
 include/linux/bug.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Tom Rini June 8, 2018, 11:19 a.m. UTC | #1
On Wed, Jun 06, 2018 at 12:38:59AM +0300, Ramon Fried wrote:

> 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))
> 
> Signed-off-by: Ramon Fried <ramon.fried@gmail.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/include/linux/bug.h b/include/linux/bug.h
index f07bb716fc..29f84168a3 100644
--- a/include/linux/bug.h
+++ b/include/linux/bug.h
@@ -20,6 +20,13 @@ 
 	unlikely(__ret_warn_on);					\
 })
 
+#define WARN(condition, format...) ({                   \
+	int __ret_warn_on = !!(condition);              \
+	if (unlikely(__ret_warn_on))                    \
+		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 */