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

Use the `DEFINE_FLEX()` helper for on-stack definitions of a flexible
structure where the size of the flexible-array member is known at
compile-time, and refactor the rest of the code, accordingly.

So, with these changes, fix the following warning:

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]

Signed-off-by: Gustavo A. R. Silva <[email protected]>
---
 fs/bcachefs/disk_accounting.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c
index 7be71952425c..381e666679d2 100644
--- a/fs/bcachefs/disk_accounting.c
+++ b/fs/bcachefs/disk_accounting.c
@@ -425,24 +425,22 @@ 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 {
-                       struct bch_replicas_usage r;
-                       u8 pad[BCH_BKEY_PTRS_MAX];
-               } u;
+               DEFINE_FLEX(struct bch_replicas_usage, u, r.devs, r.nr_devs,
+                           BCH_BKEY_PTRS_MAX);
 
-               if (!accounting_to_replicas(&u.r.r, i->pos))
+               if (!accounting_to_replicas(&u->r, i->pos))
                        continue;
 
                u64 sectors;
                bch2_accounting_mem_read_counters(acc, i - acc->k.data, 
&sectors, 1, false);
-               u.r.sectors = sectors;
+               u->sectors = sectors;
 
-               ret = darray_make_room(usage, replicas_usage_bytes(&u.r));
+               ret = darray_make_room(usage, replicas_usage_bytes(u));
                if (ret)
                        break;
 
-               memcpy(&darray_top(*usage), &u.r, replicas_usage_bytes(&u.r));
-               usage->nr += replicas_usage_bytes(&u.r);
+               memcpy(&darray_top(*usage), u, replicas_usage_bytes(u));
+               usage->nr += replicas_usage_bytes(u);
        }
        percpu_up_read(&c->mark_lock);
 
-- 
2.43.0


Reply via email to