Re: [PATCH][next] overflow: Fix direct struct member initialization in _DEFINE_FLEX()

From: Gustavo A. R. Silva
Date: Thu May 01 2025 - 19:00:56 EST



Earlier up in the file:

...
* @initializer: initializer expression (could be empty for no init).
^^^^^^^^^
*/
#define _DEFINE_FLEX(type, name, member, count, initializer...)

This argument now becomes required, which is fine, but we should keep

Nice catch!

the docs updated and double check any existing "_DEFINE_FLEX" users that
may have an empty final argument (I don't see any, so that's nice).

Yep, I build-tested it and saw no errors.


union { \
u8 bytes[struct_size_t(type, member, count)]; \
type obj; \
- } name##_u initializer; \
+ } name##_u = { .obj initializer }; \
type *name = (type *)&name##_u
/**
@@ -444,7 +444,7 @@ static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
* elements in array @member.
*/
#define DEFINE_FLEX(TYPE, NAME, MEMBER, COUNTER, COUNT) \
- _DEFINE_FLEX(TYPE, NAME, MEMBER, COUNT, = { .obj.COUNTER = COUNT, })
+ _DEFINE_FLEX(TYPE, NAME, MEMBER, COUNT, = { .COUNTER = COUNT, })
/**
* STACK_FLEX_ARRAY_SIZE() - helper macro for DEFINE_FLEX() family.

But otherwise, yes, let's do this!


Here you go :)

https://lore.kernel.org/linux-hardening/aBP0b3gfurLFDlwY@kspp/

Thanks!
-Gustavo