public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Wei Wang <wei.w.wang@intel.com>
To: arnd@arndb.de, akpm@linux-foundation.org, keescook@chromium.org,
	herbert@gondor.apana.org.au, josh@joshtriplett.org,
	jani.nikula@intel.com, corbet@lwn.net, jgg@mellanox.com,
	dmatlack@google.com, mizhang@google.com, pbonzini@redhat.com,
	seanjc@google.com
Cc: linux-kernel@vger.kernel.org, Wei Wang <wei.w.wang@intel.com>
Subject: [PATCH v1 3/3] bug: use bool for __ret_warn_on in WARN/WARN_ON
Date: Sat,  4 Mar 2023 12:19:32 +0800	[thread overview]
Message-ID: <20230304041932.847133-4-wei.w.wang@intel.com> (raw)
In-Reply-To: <20230304041932.847133-1-wei.w.wang@intel.com>

coding-style.rst documents below:
bool function return types and stack variables are always fine to use
whenever appropriate. Use of bool is encouraged to improve readability
and is often a better option than 'int' for storing boolean values.

__ret_warn_on is essentially used as boolean in WARN/WARN_ON, so change
its definition from 'int' to 'bool'.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
---
 include/asm-generic/bug.h | 12 ++++++------
 tools/include/asm/bug.h   | 10 +++++-----
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 4050b191e1a9..3a316be73f0e 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -107,7 +107,7 @@ extern __printf(1, 2) void __warn_printk(const char *fmt, ...);
 		instrumentation_end();					\
 	} while (0)
 #define WARN_ON_ONCE(condition) ({				\
-	int __ret_warn_on = !!(condition);			\
+	bool __ret_warn_on = !!(condition);			\
 	if (unlikely(__ret_warn_on))				\
 		__WARN_FLAGS(BUGFLAG_ONCE |			\
 			     BUGFLAG_TAINT(TAINT_WARN));	\
@@ -119,7 +119,7 @@ extern __printf(1, 2) void __warn_printk(const char *fmt, ...);
 
 #ifndef WARN_ON
 #define WARN_ON(condition) ({						\
-	int __ret_warn_on = !!(condition);				\
+	bool __ret_warn_on = !!(condition);				\
 	if (unlikely(__ret_warn_on))					\
 		__WARN();						\
 	unlikely(__ret_warn_on);					\
@@ -128,7 +128,7 @@ extern __printf(1, 2) void __warn_printk(const char *fmt, ...);
 
 #ifndef WARN
 #define WARN(condition, format...) ({					\
-	int __ret_warn_on = !!(condition);				\
+	bool __ret_warn_on = !!(condition);				\
 	if (unlikely(__ret_warn_on))					\
 		__WARN_printf(TAINT_WARN, format);			\
 	unlikely(__ret_warn_on);					\
@@ -136,7 +136,7 @@ extern __printf(1, 2) void __warn_printk(const char *fmt, ...);
 #endif
 
 #define WARN_TAINT(condition, taint, format...) ({			\
-	int __ret_warn_on = !!(condition);				\
+	bool __ret_warn_on = !!(condition);				\
 	if (unlikely(__ret_warn_on))					\
 		__WARN_printf(taint, format);				\
 	unlikely(__ret_warn_on);					\
@@ -164,14 +164,14 @@ extern __printf(1, 2) void __warn_printk(const char *fmt, ...);
 
 #ifndef HAVE_ARCH_WARN_ON
 #define WARN_ON(condition) ({						\
-	int __ret_warn_on = !!(condition);				\
+	bool __ret_warn_on = !!(condition);				\
 	unlikely(__ret_warn_on);					\
 })
 #endif
 
 #ifndef WARN
 #define WARN(condition, format...) ({					\
-	int __ret_warn_on = !!(condition);				\
+	bool __ret_warn_on = !!(condition);				\
 	no_printk(format);						\
 	unlikely(__ret_warn_on);					\
 })
diff --git a/tools/include/asm/bug.h b/tools/include/asm/bug.h
index 550223f0a6e6..c1f72071303b 100644
--- a/tools/include/asm/bug.h
+++ b/tools/include/asm/bug.h
@@ -8,14 +8,14 @@
 #define __WARN_printf(arg...)	do { fprintf(stderr, arg); } while (0)
 
 #define WARN(condition, format...) ({		\
-	int __ret_warn_on = !!(condition);	\
+	bool __ret_warn_on = !!(condition);	\
 	if (unlikely(__ret_warn_on))		\
 		__WARN_printf(format);		\
 	unlikely(__ret_warn_on);		\
 })
 
 #define WARN_ON(condition) ({					\
-	int __ret_warn_on = !!(condition);			\
+	bool __ret_warn_on = !!(condition);			\
 	if (unlikely(__ret_warn_on))				\
 		__WARN_printf("assertion failed at %s:%d\n",	\
 				__FILE__, __LINE__);		\
@@ -23,8 +23,8 @@
 })
 
 #define WARN_ON_ONCE(condition) ({			\
-	static int __warned;				\
-	int __ret_warn_once = !!(condition);		\
+	static bool __warned;				\
+	bool __ret_warn_once = !!(condition);		\
 							\
 	if (unlikely(__ret_warn_once && !__warned)) {	\
 		__warned = true;			\
@@ -35,7 +35,7 @@
 
 #define WARN_ONCE(condition, format...)	({	\
 	static int __warned;			\
-	int __ret_warn_once = !!(condition);	\
+	bool __ret_warn_once = !!(condition);	\
 						\
 	if (unlikely(__ret_warn_once))		\
 		if (WARN(!__warned, format)) 	\
-- 
2.27.0


      parent reply	other threads:[~2023-03-04  4:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-04  4:19 [PATCH v1 0/3] Regarding using 'bool' appropriately Wei Wang
2023-03-04  4:19 ` [PATCH v1 1/3] security: keys: don't use data type as variable name Wei Wang
2023-03-11 22:13   ` Jarkko Sakkinen
2023-03-04  4:19 ` [PATCH v1 2/3] Documentation/CodingStyle: do not use data type names as variable names Wei Wang
2023-03-04 15:01   ` Jonathan Corbet
2023-03-06 11:03     ` Wang, Wei W
2023-03-04  4:19 ` Wei Wang [this message]

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=20230304041932.847133-4-wei.w.wang@intel.com \
    --to=wei.w.wang@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=corbet@lwn.net \
    --cc=dmatlack@google.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=jani.nikula@intel.com \
    --cc=jgg@mellanox.com \
    --cc=josh@joshtriplett.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mizhang@google.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    /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