public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Ramon Fried <ramon.fried@linaro.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] bug.h: introduce WARN_ONCE
Date: Mon, 28 May 2018 12:44:30 +0300	[thread overview]
Message-ID: <20180528094430.2440-1-ramon.fried@gmail.com> (raw)

Add WARN_ONCE definition to allow single time notification
of warnings to the user.

Signed-off-by: Ramon Fried <ramon.fried@gmail.com>
---
 include/linux/bug.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/include/linux/bug.h b/include/linux/bug.h
index f07bb716fc0..67b6057a22a 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))                    \
+		__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 */
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

             reply	other threads:[~2018-05-28  9:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-28  9:44 Ramon Fried [this message]
2018-05-28 23:21 ` [U-Boot] [PATCH] bug.h: introduce WARN_ONCE Masahiro Yamada
2018-05-29 10:34   ` Ramon Fried

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180528094430.2440-1-ramon.fried@gmail.com \
    --to=ramon.fried@linaro.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox