Skip to content

Commit 9a93048

Browse files
committed
overflow: Clarify expectations for getting DEFINE_FLEX variable sizes
Mention the use of __member_size() for DEFINE_FLEX variables as a hint for getting at the compile-time size of the resulting flexible array member. Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Link: https://lore.kernel.org/r/20250416172911.work.854-kees@kernel.org Signed-off-by: Kees Cook <kees@kernel.org>
1 parent a510c18 commit 9a93048

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

include/linux/overflow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
419419
* Define a zeroed, on-stack, instance of @type structure with a trailing
420420
* flexible array member.
421421
* Use __struct_size(@name) to get compile-time size of it afterwards.
422+
* Use __member_size(@name->member) to get compile-time size of @name members.
422423
*/
423424
#define DEFINE_RAW_FLEX(type, name, member, count) \
424425
_DEFINE_FLEX(type, name, member, count, = {})
@@ -436,6 +437,7 @@ static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
436437
* Define a zeroed, on-stack, instance of @TYPE structure with a trailing
437438
* flexible array member.
438439
* Use __struct_size(@NAME) to get compile-time size of it afterwards.
440+
* Use __member_size(@NAME->member) to get compile-time size of @NAME members.
439441
*/
440442
#define DEFINE_FLEX(TYPE, NAME, MEMBER, COUNTER, COUNT) \
441443
_DEFINE_FLEX(TYPE, NAME, MEMBER, COUNT, = { .obj.COUNTER = COUNT, })

0 commit comments

Comments
 (0)