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

bcache: Avoid -Wflex-array-member-not-at-end warning

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are
getting ready to enable it, globally.

Use the new TRAILING_OVERLAP() helper to fix the following warning:

drivers/md/bcache/bset.h:330:27: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

This helper creates a union between a flexible-array member (FAM) and a
set of MEMBERS that would otherwise follow it.

This overlays the trailing MEMBER struct btree_iter_set stack_data[MAX_BSETS];
onto the FAM struct btree_iter::data[], while keeping the FAM and the start
of MEMBER aligned.

The static_assert() ensures this alignment remains, and it's
intentionally placed immediately after the corresponding structures --no
blank line in between.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Coly Li <colyli@fnnas.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Gustavo A. R. Silva and committed by
Jens Axboe
699122b5 c0c80821

+6 -2
+6 -2
drivers/md/bcache/bset.h
··· 327 327 /* Fixed-size btree_iter that can be allocated on the stack */ 328 328 329 329 struct btree_iter_stack { 330 - struct btree_iter iter; 331 - struct btree_iter_set stack_data[MAX_BSETS]; 330 + /* Must be last as it ends in a flexible-array member. */ 331 + TRAILING_OVERLAP(struct btree_iter, iter, data, 332 + struct btree_iter_set stack_data[MAX_BSETS]; 333 + ); 332 334 }; 335 + static_assert(offsetof(struct btree_iter_stack, iter.data) == 336 + offsetof(struct btree_iter_stack, stack_data)); 333 337 334 338 typedef bool (*ptr_filter_fn)(struct btree_keys *b, const struct bkey *k); 335 339