[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f9f20ad9362972ef920dd9aecd7b98ab345ee866.1739957534.git.gustavoars@kernel.org>
Date: Mon, 24 Feb 2025 20:31:26 +1030
From: "Gustavo A. R. Silva" <gustavoars@...nel.org>
To: Coly Li <colyli@...nel.org>,
Kent Overstreet <kent.overstreet@...ux.dev>
Cc: linux-bcache@...r.kernel.org, linux-kernel@...r.kernel.org,
"Gustavo A. R. Silva" <gustavoars@...nel.org>,
linux-hardening@...r.kernel.org
Subject: [PATCH 8/8][next] bcache: Avoid -Wflex-array-member-not-at-end
warnings
-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@...nel.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
Powered by blists - more mailing lists