lkml.org 
[lkml]   [2023]   [Mar]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v1 3/3] bug: use bool for __ret_warn_on in WARN/WARN_ON
Date
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
\
 
 \ /
  Last update: 2023-03-27 00:44    [W:0.197 / U:0.000 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site