bcachefs: Avoid -Wflex-array-member-not-at-end warnings
authorGustavo A. R. Silva <gustavoars@kernel.org>
Wed, 30 Apr 2025 19:22:01 +0000 (13:22 -0600)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:38 +0000 (20:14 -0400)
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are
getting ready to enable it, globally.

Refactor a couple of structs that contain flexible arrays in the
middle by replacing them with unions.

So, with these changes, fix the following warnings:

fs/bcachefs/disk_accounting.c:429:51: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
fs/bcachefs/ec_types.h:8:41: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/disk_accounting.c
fs/bcachefs/ec_types.h
fs/bcachefs/journal_io.c
fs/bcachefs/journal_reclaim.c

index e399237e124ad245d0ed2830d09f62fdf6366211..195dc3fcec1d815f71ca5e5764779c07a3a19a94 100644 (file)
@@ -287,7 +287,7 @@ static inline bool accounting_to_replicas(struct bch_replicas_entry_v1 *r, struc
 
 static int bch2_accounting_update_sb_one(struct bch_fs *c, struct bpos p)
 {
-       struct bch_replicas_padded r;
+       union bch_replicas_padded r;
        return accounting_to_replicas(&r.e, p)
                ? bch2_mark_replicas(c, &r.e)
                : 0;
@@ -361,7 +361,7 @@ err:
 int bch2_accounting_mem_insert(struct bch_fs *c, struct bkey_s_c_accounting a,
                               enum bch_accounting_mode mode)
 {
-       struct bch_replicas_padded r;
+       union bch_replicas_padded r;
 
        if (mode != BCH_ACCOUNTING_read &&
            accounting_to_replicas(&r.e, a.k->p) &&
@@ -379,7 +379,7 @@ int bch2_accounting_mem_insert(struct bch_fs *c, struct bkey_s_c_accounting a,
 int bch2_accounting_mem_insert_locked(struct bch_fs *c, struct bkey_s_c_accounting a,
                               enum bch_accounting_mode mode)
 {
-       struct bch_replicas_padded r;
+       union bch_replicas_padded r;
 
        if (mode != BCH_ACCOUNTING_read &&
            accounting_to_replicas(&r.e, a.k->p) &&
@@ -438,10 +438,12 @@ int bch2_fs_replicas_usage_read(struct bch_fs *c, darray_char *usage)
 
        percpu_down_read(&c->mark_lock);
        darray_for_each(acc->k, i) {
-               struct {
+               union {
+                       u8 bytes[struct_size_t(struct bch_replicas_usage, r.devs,
+                                              BCH_BKEY_PTRS_MAX)];
                        struct bch_replicas_usage r;
-                       u8 pad[BCH_BKEY_PTRS_MAX];
                } u;
+               u.r.r.nr_devs = BCH_BKEY_PTRS_MAX;
 
                if (!accounting_to_replicas(&u.r.r, i->pos))
                        continue;
@@ -640,7 +642,7 @@ static int bch2_disk_accounting_validate_late(struct btree_trans *trans,
 
        switch (acc->type) {
        case BCH_DISK_ACCOUNTING_replicas: {
-               struct bch_replicas_padded r;
+               union bch_replicas_padded r;
                __accounting_to_replicas(&r.e, acc);
 
                for (unsigned i = 0; i < r.e.nr_devs; i++)
index 06144bfd9c19fd35202d33374e3e94d9920958da..809446c789518b18d0752dbe9d654f87f2acc4ff 100644 (file)
@@ -4,9 +4,10 @@
 
 #include "bcachefs_format.h"
 
-struct bch_replicas_padded {
+union bch_replicas_padded {
+       u8                              bytes[struct_size_t(struct bch_replicas_entry_v1,
+                                                           devs, BCH_BKEY_PTRS_MAX)];
        struct bch_replicas_entry_v1    e;
-       u8                              pad[BCH_BKEY_PTRS_MAX];
 };
 
 struct stripe {
@@ -28,7 +29,7 @@ struct gc_stripe {
        u16                     block_sectors[BCH_BKEY_PTRS_MAX];
        struct bch_extent_ptr   ptrs[BCH_BKEY_PTRS_MAX];
 
-       struct bch_replicas_padded r;
+       union bch_replicas_padded r;
 };
 
 #endif /* _BCACHEFS_EC_TYPES_H */
index 8f38e9485cd854847080084eb0ac2e5cacac28d3..be86fd21de2a65325c63fb03ac92d2dfbf4d45f3 100644 (file)
@@ -1406,7 +1406,7 @@ int bch2_journal_read(struct bch_fs *c,
        }
 
        genradix_for_each(&c->journal_entries, radix_iter, _i) {
-               struct bch_replicas_padded replicas = {
+               union bch_replicas_padded replicas = {
                        .e.data_type = BCH_DATA_journal,
                        .e.nr_devs = 0,
                        .e.nr_required = 1,
@@ -1634,7 +1634,7 @@ static CLOSURE_CALLBACK(journal_write_done)
        closure_type(w, struct journal_buf, io);
        struct journal *j = container_of(w, struct journal, buf[w->idx]);
        struct bch_fs *c = container_of(j, struct bch_fs, journal);
-       struct bch_replicas_padded replicas;
+       union bch_replicas_padded replicas;
        u64 seq = le64_to_cpu(w->data->seq);
        int err = 0;
 
@@ -2057,7 +2057,7 @@ CLOSURE_CALLBACK(bch2_journal_write)
        closure_type(w, struct journal_buf, io);
        struct journal *j = container_of(w, struct journal, buf[w->idx]);
        struct bch_fs *c = container_of(j, struct bch_fs, journal);
-       struct bch_replicas_padded replicas;
+       union bch_replicas_padded replicas;
        unsigned nr_rw_members = dev_mask_nr(&c->rw_devs[BCH_DATA_journal]);
        int ret;
 
index bb339be54e7b6fae6b6a656e6f97cfac3bc8eeb3..ce9e0bd7ec4fa9f0311954daffc2b119bbc40f33 100644 (file)
@@ -963,7 +963,7 @@ int bch2_journal_flush_device_pins(struct journal *j, int dev_idx)
        seq = 0;
        spin_lock(&j->lock);
        while (!ret) {
-               struct bch_replicas_padded replicas;
+               union bch_replicas_padded replicas;
 
                seq = max(seq, journal_last_seq(j));
                if (seq >= j->pin.back)