]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcache: Avoid -Wflex-array-member-not-at-end warning
authorGustavo A. R. Silva <gustavoars@kernel.org>
Thu, 13 Nov 2025 05:36:30 +0000 (13:36 +0800)
committerJens Axboe <axboe@kernel.dk>
Thu, 13 Nov 2025 16:18:06 +0000 (09:18 -0700)
-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>
drivers/md/bcache/bset.h

index 011f6062c4c04f8bffe0ef61465c15fa28ae23fd..6ee2c6a506a263f106d21c7cb76d8487607c5543 100644 (file)
@@ -327,9 +327,13 @@ struct btree_iter {
 /* Fixed-size btree_iter that can be allocated on the stack */
 
 struct btree_iter_stack {
-       struct btree_iter iter;
-       struct btree_iter_set stack_data[MAX_BSETS];
+       /* Must be last as it ends in a flexible-array member. */
+       TRAILING_OVERLAP(struct btree_iter, iter, data,
+               struct btree_iter_set stack_data[MAX_BSETS];
+       );
 };
+static_assert(offsetof(struct btree_iter_stack, iter.data) ==
+             offsetof(struct btree_iter_stack, stack_data));
 
 typedef bool (*ptr_filter_fn)(struct btree_keys *b, const struct bkey *k);