mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: Coly Li <colyli@kernel.org>, Kent Overstreet <kent.overstreet@linux.dev>
Cc: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-hardening@vger.kernel.org
Subject: [PATCH 8/8][next] bcache: Avoid -Wflex-array-member-not-at-end warnings
Date: Mon, 24 Feb 2025 20:31:26 +1030	[thread overview]
Message-ID: <f9f20ad9362972ef920dd9aecd7b98ab345ee866.1739957534.git.gustavoars@kernel.org> (raw)
In-Reply-To: <cover.1739957534.git.gustavoars@kernel.org>

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

Change the type of the middle struct members currently causing trouble
from `struct bio` to `struct bio_hdr`.

We also use `container_of()` whenever we need to retrieve a pointer to
the flexible structure `struct bio`, through which we can access the
flexible-array member in it, if necessary.

With these changes fix 112 of the following warnings:

drivers/md/bcache/bcache.h:233:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/md/bcache/bcache.h:241:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/md/bcache/bcache.h:242:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/md/bcache/bcache.h:308:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/md/bcache/bcache.h:422:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/md/bcache/bcache.h:639:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/md/bcache/journal.h:152:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/md/bcache/journal.h:156:33: 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>
---
 drivers/md/bcache/bcache.h  |  4 ++--
 drivers/md/bcache/journal.c | 10 +++++-----
 drivers/md/bcache/journal.h |  4 ++--
 drivers/md/bcache/super.c   |  8 +++++---
 4 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
index 785b0d9008fa..328023e90eb2 100644
--- a/drivers/md/bcache/bcache.h
+++ b/drivers/md/bcache/bcache.h
@@ -305,7 +305,7 @@ struct cached_dev {
 
 	struct cache_sb		sb;
 	struct cache_sb_disk	*sb_disk;
-	struct bio		sb_bio;
+	struct bio_hdr		sb_bio;
 	struct bio_vec		sb_bv[1];
 	struct closure		sb_write;
 	struct semaphore	sb_write_mutex;
@@ -419,7 +419,7 @@ struct cache {
 	struct cache_set	*set;
 	struct cache_sb		sb;
 	struct cache_sb_disk	*sb_disk;
-	struct bio		sb_bio;
+	struct bio_hdr		sb_bio;
 	struct bio_vec		sb_bv[1];
 
 	struct kobject		kobj;
diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
index 7ff14bd2feb8..2ead129f7758 100644
--- a/drivers/md/bcache/journal.c
+++ b/drivers/md/bcache/journal.c
@@ -36,7 +36,7 @@ static int journal_read_bucket(struct cache *ca, struct list_head *list,
 			       unsigned int bucket_index)
 {
 	struct journal_device *ja = &ca->journal;
-	struct bio *bio = &ja->bio;
+	struct bio *bio = container_of(&ja->bio, struct bio, __hdr);
 
 	struct journal_replay *i;
 	struct jset *j, *data = ca->set->journal.w[0].data;
@@ -571,7 +571,7 @@ static void btree_flush_write(struct cache_set *c)
 static void journal_discard_endio(struct bio *bio)
 {
 	struct journal_device *ja =
-		container_of(bio, struct journal_device, discard_bio);
+		container_of(&bio->__hdr, struct journal_device, discard_bio);
 	struct cache *ca = container_of(ja, struct cache, journal);
 
 	atomic_set(&ja->discard_in_flight, DISCARD_DONE);
@@ -585,13 +585,13 @@ static void journal_discard_work(struct work_struct *work)
 	struct journal_device *ja =
 		container_of(work, struct journal_device, discard_work);
 
-	submit_bio(&ja->discard_bio);
+	submit_bio(container_of(&ja->discard_bio, struct bio, __hdr));
 }
 
 static void do_journal_discard(struct cache *ca)
 {
 	struct journal_device *ja = &ca->journal;
-	struct bio *bio = &ja->discard_bio;
+	struct bio *bio = container_of(&ja->discard_bio, struct bio, __hdr);
 
 	if (!ca->discard) {
 		ja->discard_idx = ja->last_idx;
@@ -787,7 +787,7 @@ static CLOSURE_CALLBACK(journal_write_unlocked)
 
 	for (i = 0; i < KEY_PTRS(k); i++) {
 		ca = c->cache;
-		bio = &ca->journal.bio;
+		bio = container_of(&ca->journal.bio, struct bio, __hdr);
 
 		atomic_long_add(sectors, &ca->meta_sectors_written);
 
diff --git a/drivers/md/bcache/journal.h b/drivers/md/bcache/journal.h
index cd316b4a1e95..b4ff5269aee3 100644
--- a/drivers/md/bcache/journal.h
+++ b/drivers/md/bcache/journal.h
@@ -149,11 +149,11 @@ struct journal_device {
 	atomic_t		discard_in_flight;
 
 	struct work_struct	discard_work;
-	struct bio		discard_bio;
+	struct bio_hdr		discard_bio;
 	struct bio_vec		discard_bv;
 
 	/* Bio for journal reads/writes to this device */
-	struct bio		bio;
+	struct bio_hdr		bio;
 	struct bio_vec		bv[8];
 };
 
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index e42f1400cea9..cd1342355cf2 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -337,7 +337,7 @@ static CLOSURE_CALLBACK(bch_write_bdev_super_unlock)
 void bch_write_bdev_super(struct cached_dev *dc, struct closure *parent)
 {
 	struct closure *cl = &dc->sb_write;
-	struct bio *bio = &dc->sb_bio;
+	struct bio *bio = container_of(&dc->sb_bio, struct bio, __hdr);
 
 	down(&dc->sb_write_mutex);
 	closure_init(cl, parent);
@@ -374,7 +374,7 @@ void bcache_write_super(struct cache_set *c)
 {
 	struct closure *cl = &c->sb_write;
 	struct cache *ca = c->cache;
-	struct bio *bio = &ca->sb_bio;
+	struct bio *bio = container_of(&ca->sb_bio, struct bio, __hdr);
 	unsigned int version = BCACHE_SB_VERSION_CDEV_WITH_UUID;
 
 	down(&c->sb_write_mutex);
@@ -2230,7 +2230,9 @@ static int cache_alloc(struct cache *ca)
 	__module_get(THIS_MODULE);
 	kobject_init(&ca->kobj, &bch_cache_ktype);
 
-	bio_init(&ca->journal.bio, NULL, ca->journal.bio.bi_inline_vecs, 8, 0);
+	bio_init(container_of(&ca->journal.bio, struct bio, __hdr), NULL,
+		 container_of(&ca->journal.bio, struct bio, __hdr)->bi_inline_vecs,
+		 8, 0);
 
 	/*
 	 * when ca->sb.njournal_buckets is not zero, journal exists,
-- 
2.43.0


  parent reply	other threads:[~2025-02-24 10:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-24  9:53 [PATCH 0/8][next] Avoid a couple hundred " Gustavo A. R. Silva
2025-02-24  9:55 ` [PATCH 1/8][next] block: blk_types.h: Use struct_group_tagged() in flex struct bio Gustavo A. R. Silva
2025-02-24 16:39   ` Christoph Hellwig
2025-02-24  9:56 ` [PATCH 2/8][next] md/raid5-ppl: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2025-02-24  9:57 ` [PATCH 3/8][next] xfs: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2025-02-24 19:12   ` Darrick J. Wong
2025-02-24 21:45   ` Dave Chinner
2025-02-24  9:58 ` [PATCH 4/8][next] erofs: " Gustavo A. R. Silva
2025-02-24  9:59 ` [PATCH 5/8][next] btrfs: " Gustavo A. R. Silva
2025-02-24 10:00 ` [PATCH 6/8][next] nvme: target: " Gustavo A. R. Silva
2025-02-24 14:19   ` Christoph Hellwig
2025-02-25  1:51     ` Gustavo A. R. Silva
2025-02-24 10:00 ` [PATCH 7/8][next] md/raid5: " Gustavo A. R. Silva
2025-02-24 10:01 ` Gustavo A. R. Silva [this message]
2025-02-24 14:04   ` [PATCH 8/8][next] bcache: " Coly Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f9f20ad9362972ef920dd9aecd7b98ab345ee866.1739957534.git.gustavoars@kernel.org \
    --to=gustavoars@kernel.org \
    --cc=colyli@kernel.org \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®