Skip to content

Commit

Permalink
spl: cmn_err_once() should be usable in brace-less if else statements
Browse files Browse the repository at this point in the history
Commit 1191387 (openzfs#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 <behlendorf1@llnl.gov>
Signed-off-by: Attila Fülöp <attila@fueloep.org>
Closes openzfs#14629
  • Loading branch information
AttilaFueloep authored and lundman committed Mar 17, 2023
1 parent ea9bddb commit 7cda0e4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions include/os/freebsd/spl/sys/cmn_err.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
8 changes: 4 additions & 4 deletions include/os/linux/spl/sys/cmn_err.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
16 changes: 8 additions & 8 deletions lib/libspl/include/sys/cmn_err.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,35 @@
#include <atomic.h>

#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

0 comments on commit 7cda0e4

Please sign in to comment.