From 5f3611121dd844f81a27d15ed2db770dea189d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20F=C3=BCl=C3=B6p?= Date: Wed, 15 Mar 2023 19:13:25 +0100 Subject: [PATCH] spl: cmn_err_once() should be usable in brace-less if else statements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 11913870 (#14567) added cmn_err_once() by #define'ing a compound statement but failed to consider usage in a single statement brace-less if else. Fix the problem by using the common "do {} while (0)" construct. Reviewed-by: Brian Behlendorf Signed-off-by: Attila Fülöp Closes #14629 --- include/os/freebsd/spl/sys/cmn_err.h | 16 ++++++++-------- include/os/linux/spl/sys/cmn_err.h | 8 ++++---- lib/libspl/include/sys/cmn_err.h | 16 ++++++++-------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/os/freebsd/spl/sys/cmn_err.h b/include/os/freebsd/spl/sys/cmn_err.h index dd3da7da20..87fce4955b 100644 --- a/include/os/freebsd/spl/sys/cmn_err.h +++ b/include/os/freebsd/spl/sys/cmn_err.h @@ -75,36 +75,36 @@ extern void panic(const char *, ...) __attribute__((format(printf, 1, 2), __noreturn__)); #define cmn_err_once(ce, ...) \ -{ \ +do { \ static volatile uint32_t printed = 0; \ if (atomic_cas_32(&printed, 0, 1) == 0) { \ cmn_err(ce, __VA_ARGS__); \ } \ -} +} while (0) #define vcmn_err_once(ce, fmt, ap) \ -{ \ +do { \ static volatile uint32_t printed = 0; \ if (atomic_cas_32(&printed, 0, 1) == 0) { \ vcmn_err(ce, fmt, ap); \ } \ -} +} while (0) #define zcmn_err_once(zone, ce, ...) \ -{ \ +do { \ static volatile uint32_t printed = 0; \ if (atomic_cas_32(&printed, 0, 1) == 0) { \ zcmn_err(zone, ce, __VA_ARGS__); \ } \ -} +} while (0) #define vzcmn_err_once(zone, ce, fmt, ap) \ -{ \ +do { \ static volatile uint32_t printed = 0; \ if (atomic_cas_32(&printed, 0, 1) == 0) { \ vzcmn_err(zone, ce, fmt, ap); \ } \ -} +} while (0) #endif /* !_ASM */ diff --git a/include/os/linux/spl/sys/cmn_err.h b/include/os/linux/spl/sys/cmn_err.h index 7ca2a86be9..bd407559cc 100644 --- a/include/os/linux/spl/sys/cmn_err.h +++ b/include/os/linux/spl/sys/cmn_err.h @@ -47,19 +47,19 @@ extern void vpanic(const char *, va_list) #define fm_panic panic #define cmn_err_once(ce, ...) \ -{ \ +do { \ static volatile uint32_t printed = 0; \ if (atomic_cas_32(&printed, 0, 1) == 0) { \ cmn_err(ce, __VA_ARGS__); \ } \ -} +} while (0) #define vcmn_err_once(ce, fmt, ap) \ -{ \ +do { \ static volatile uint32_t printed = 0; \ if (atomic_cas_32(&printed, 0, 1) == 0) { \ vcmn_err(ce, fmt, ap); \ } \ -} +} while (0) #endif /* SPL_CMN_ERR_H */ diff --git a/lib/libspl/include/sys/cmn_err.h b/lib/libspl/include/sys/cmn_err.h index 6c71dcb8ec..6a29e6cff2 100644 --- a/lib/libspl/include/sys/cmn_err.h +++ b/lib/libspl/include/sys/cmn_err.h @@ -30,35 +30,35 @@ #include #define cmn_err_once(ce, ...) \ -{ \ +do { \ static volatile uint32_t printed = 0; \ if (atomic_cas_32(&printed, 0, 1) == 0) { \ cmn_err(ce, __VA_ARGS__); \ } \ -} +} while (0) #define vcmn_err_once(ce, fmt, ap) \ -{ \ +do { \ static volatile uint32_t printed = 0; \ if (atomic_cas_32(&printed, 0, 1) == 0) { \ vcmn_err(ce, fmt, ap); \ } \ -} +} while (0) #define zcmn_err_once(zone, ce, ...) \ -{ \ +do { \ static volatile uint32_t printed = 0; \ if (atomic_cas_32(&printed, 0, 1) == 0) { \ zcmn_err(zone, ce, __VA_ARGS__); \ } \ -} +} while (0) #define vzcmn_err_once(zone, ce, fmt, ap) \ -{ \ +do { \ static volatile uint32_t printed = 0; \ if (atomic_cas_32(&printed, 0, 1) == 0) { \ vzcmn_err(zone, ce, fmt, ap); \ } \ -} +} while (0) #endif