From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ramon Fried Date: Tue, 29 May 2018 15:46:39 +0300 Subject: [U-Boot] [PATCH v2] bug.h: introduce WARN_ONCE Message-ID: <20180529124639.13172-1-ramon.fried@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de From: Ramon Fried Add WARN_ONCE definition to allow single time notification of warnings to the user. Change-Id: If14d878dba04f3c976c0c2ae079a0f7642047006 --- v2: accidently commited the wrong file. noticed by Masahiro Yamada include/linux/bug.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/bug.h b/include/linux/bug.h index f07bb716fc0..e43871dee44 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 */ -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project