sys/sysctl.h: Fix wrong assertion with multiple access flags

With multiple flags passed in, e.g., CTLFLAG_RD | CTLFLAG_CAPRD, due to
the precedence rules, this will result in false positive assertion. Fix
that by surrounding the replacement lists with parentheses.

Reviewed by:	imp, erj
Fixes:		10a1e981d4 iflib: mark isc_driver_version as constant
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D45531

(cherry picked from commit 23f4131ad6)
This commit is contained in:
Zhenlei Huang 2024-06-08 11:21:11 +08:00
parent f70581ff7d
commit 9cd77bd9c6

View file

@ -395,14 +395,14 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
#define SYSCTL_CONST_STRING(parent, nbr, name, access, arg, descr) \
SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING | CTLFLAG_MPSAFE | (access),\
__DECONST(char *, arg), 0, sysctl_handle_string, "A", descr); \
CTASSERT(!(access & CTLFLAG_WR)); \
CTASSERT(!((access) & CTLFLAG_WR)); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING)
#define SYSCTL_ADD_CONST_STRING(ctx, parent, nbr, name, access, arg, descr) \
({ \
char *__arg = __DECONST(char *, arg); \
CTASSERT(!(access & CTLFLAG_WR)); \
CTASSERT(!((access) & CTLFLAG_WR)); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING); \
sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING | \