public inbox for linux-bcachefs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] bcachefs: Avoid -Wflex-array-member-not-at-end warning
@ 2025-04-30  1:15 Gustavo A. R. Silva
  2025-04-30  1:40 ` Kent Overstreet
  0 siblings, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2025-04-30  1:15 UTC (permalink / raw)
  To: Kent Overstreet
  Cc: linux-bcachefs, linux-kernel, Gustavo A. R. Silva,
	linux-hardening

-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 <gustavoars@kernel.org>
---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-04-30 18:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-30  1:15 [PATCH][next] bcachefs: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2025-04-30  1:40 ` Kent Overstreet
2025-04-30 18:27   ` Gustavo A. R. Silva
2025-04-30 18:32     ` Kent Overstreet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox