From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: Gao Xiang <xiang@kernel.org>, Chao Yu <chao@kernel.org>,
Yue Hu <zbestahu@gmail.com>,
Jeffle Xu <jefflexu@linux.alibaba.com>,
Sandeep Dhavale <dhavale@google.com>
Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-hardening@vger.kernel.org
Subject: [PATCH 4/8][next] erofs: Avoid -Wflex-array-member-not-at-end warnings
Date: Mon, 24 Feb 2025 20:28:43 +1030 [thread overview]
Message-ID: <334f60e884cc0314ef98731e60a1b419e462e2d2.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 member 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 the following warnings:
fs/erofs/fileio.c:10:20: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
fs/erofs/fscache.c:179:20: 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/erofs/fileio.c | 25 +++++++++++++++----------
fs/erofs/fscache.c | 13 +++++++------
2 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/fs/erofs/fileio.c b/fs/erofs/fileio.c
index 0ffd1c63beeb..3080963caf78 100644
--- a/fs/erofs/fileio.c
+++ b/fs/erofs/fileio.c
@@ -7,7 +7,7 @@
struct erofs_fileio_rq {
struct bio_vec bvecs[16];
- struct bio bio;
+ struct bio_hdr bio;
struct kiocb iocb;
struct super_block *sb;
};
@@ -26,20 +26,21 @@ static void erofs_fileio_ki_complete(struct kiocb *iocb, long ret)
if (ret > 0) {
if (ret != rq->bio.bi_iter.bi_size) {
- bio_advance(&rq->bio, ret);
- zero_fill_bio(&rq->bio);
+ bio_advance(container_of(&rq->bio, struct bio, __hdr),
+ ret);
+ zero_fill_bio(container_of(&rq->bio, struct bio, __hdr));
}
ret = 0;
}
if (rq->bio.bi_end_io) {
- rq->bio.bi_end_io(&rq->bio);
+ rq->bio.bi_end_io(container_of(&rq->bio, struct bio, __hdr));
} else {
- bio_for_each_folio_all(fi, &rq->bio) {
+ bio_for_each_folio_all(fi, container_of(&rq->bio, struct bio, __hdr)) {
DBG_BUGON(folio_test_uptodate(fi.folio));
erofs_onlinefolio_end(fi.folio, ret);
}
}
- bio_uninit(&rq->bio);
+ bio_uninit(container_of(&rq->bio, struct bio, __hdr));
kfree(rq);
}
@@ -68,7 +69,8 @@ static struct erofs_fileio_rq *erofs_fileio_rq_alloc(struct erofs_map_dev *mdev)
struct erofs_fileio_rq *rq = kzalloc(sizeof(*rq),
GFP_KERNEL | __GFP_NOFAIL);
- bio_init(&rq->bio, NULL, rq->bvecs, ARRAY_SIZE(rq->bvecs), REQ_OP_READ);
+ bio_init(container_of(&rq->bio, struct bio, __hdr), NULL, rq->bvecs,
+ ARRAY_SIZE(rq->bvecs), REQ_OP_READ);
rq->iocb.ki_filp = mdev->m_dif->file;
rq->sb = mdev->m_sb;
return rq;
@@ -76,12 +78,13 @@ static struct erofs_fileio_rq *erofs_fileio_rq_alloc(struct erofs_map_dev *mdev)
struct bio *erofs_fileio_bio_alloc(struct erofs_map_dev *mdev)
{
- return &erofs_fileio_rq_alloc(mdev)->bio;
+ return container_of(&erofs_fileio_rq_alloc(mdev)->bio, struct bio, __hdr);
}
void erofs_fileio_submit_bio(struct bio *bio)
{
- return erofs_fileio_rq_submit(container_of(bio, struct erofs_fileio_rq,
+ return erofs_fileio_rq_submit(container_of(&bio->__hdr,
+ struct erofs_fileio_rq,
bio));
}
@@ -150,7 +153,9 @@ static int erofs_fileio_scan_folio(struct erofs_fileio *io, struct folio *folio)
}
if (!attached++)
erofs_onlinefolio_split(folio);
- if (!bio_add_folio(&io->rq->bio, folio, len, cur))
+ if (!bio_add_folio(container_of(&io->rq->bio,
+ struct bio, __hdr),
+ folio, len, cur))
goto io_retry;
io->dev.m_pa += len;
}
diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
index ce3d8737df85..719ec96c8f22 100644
--- a/fs/erofs/fscache.c
+++ b/fs/erofs/fscache.c
@@ -176,7 +176,7 @@ static int erofs_fscache_read_io_async(struct fscache_cookie *cookie,
struct erofs_fscache_bio {
struct erofs_fscache_io io;
- struct bio bio; /* w/o bdev to share bio_add_page/endio() */
+ struct bio_hdr bio; /* w/o bdev to share bio_add_page/endio() */
struct bio_vec bvecs[BIO_MAX_VECS];
};
@@ -187,7 +187,7 @@ static void erofs_fscache_bio_endio(void *priv,
if (IS_ERR_VALUE(transferred_or_error))
io->bio.bi_status = errno_to_blk_status(transferred_or_error);
- io->bio.bi_end_io(&io->bio);
+ io->bio.bi_end_io(container_of(&io->bio, struct bio, __hdr));
BUILD_BUG_ON(offsetof(struct erofs_fscache_bio, io) != 0);
erofs_fscache_io_put(&io->io);
}
@@ -197,17 +197,18 @@ struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev)
struct erofs_fscache_bio *io;
io = kmalloc(sizeof(*io), GFP_KERNEL | __GFP_NOFAIL);
- bio_init(&io->bio, NULL, io->bvecs, BIO_MAX_VECS, REQ_OP_READ);
+ bio_init(container_of(&io->bio, struct bio, __hdr), NULL, io->bvecs,
+ BIO_MAX_VECS, REQ_OP_READ);
io->io.private = mdev->m_dif->fscache->cookie;
io->io.end_io = erofs_fscache_bio_endio;
refcount_set(&io->io.ref, 1);
- return &io->bio;
+ return container_of(&io->bio, struct bio, __hdr);
}
void erofs_fscache_submit_bio(struct bio *bio)
{
- struct erofs_fscache_bio *io = container_of(bio,
- struct erofs_fscache_bio, bio);
+ struct erofs_fscache_bio *io =
+ container_of(&bio->__hdr, struct erofs_fscache_bio, bio);
int ret;
iov_iter_bvec(&io->io.iter, ITER_DEST, io->bvecs, bio->bi_vcnt,
--
2.43.0
next prev parent reply other threads:[~2025-02-24 9:58 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 ` Gustavo A. R. Silva [this message]
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 ` [PATCH 8/8][next] bcache: " Gustavo A. R. Silva
2025-02-24 14:04 ` 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=334f60e884cc0314ef98731e60a1b419e462e2d2.1739957534.git.gustavoars@kernel.org \
--to=gustavoars@kernel.org \
--cc=chao@kernel.org \
--cc=dhavale@google.com \
--cc=jefflexu@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xiang@kernel.org \
--cc=zbestahu@gmail.com \
/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®