Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

compiler.h: Fix undefined BUILD_BUG_ON_ZERO()

<linux/compiler.h> defines __must_be_array() and __must_be_cstr() and
both expand to BUILD_BUG_ON_ZERO(), but <linux/build_bug.h> defines
BUILD_BUG_ON_ZERO(). Including <linux/build_bug.h> in
<linux/compiler.h> would create a cyclic dependency as
<linux/build_bug.h> already includes <linux/compiler.h>.

Fix that by defining __BUILD_BUG_ON_ZERO_MSG() in <linux/compiler.h>
and using that for __must_be_array() and __must_be_cstr().

Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Link: https://lore.kernel.org/r/20241115204602.249590-1-philipp.reisner@linbit.com
Signed-off-by: Kees Cook <kees@kernel.org>

authored by

Philipp Reisner and committed by
Kees Cook
d7a516c6 a508ef4b

+9 -2
+9 -2
include/linux/compiler.h
··· 239 239 240 240 #endif /* __ASSEMBLY__ */ 241 241 242 + #ifdef __CHECKER__ 243 + #define __BUILD_BUG_ON_ZERO_MSG(e, msg) (0) 244 + #else /* __CHECKER__ */ 245 + #define __BUILD_BUG_ON_ZERO_MSG(e, msg) ((int)sizeof(struct {_Static_assert(!(e), msg);})) 246 + #endif /* __CHECKER__ */ 247 + 242 248 /* &a[0] degrades to a pointer: a different type from an array */ 243 - #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) 249 + #define __must_be_array(a) __BUILD_BUG_ON_ZERO_MSG(__same_type((a), &(a)[0]), "must be array") 244 250 245 251 /* Require C Strings (i.e. NUL-terminated) lack the "nonstring" attribute. */ 246 - #define __must_be_cstr(p) BUILD_BUG_ON_ZERO(__annotated(p, nonstring)) 252 + #define __must_be_cstr(p) \ 253 + __BUILD_BUG_ON_ZERO_MSG(__annotated(p, nonstring), "must be cstr (NUL-terminated)") 247 254 248 255 /* 249 256 * This returns a constant expression while determining if an argument is