* [PATCH 0/8][next] Avoid a couple hundred -Wflex-array-member-not-at-end warnings
@ 2025-02-24 9:53 Gustavo A. R. Silva
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 10:00 ` [PATCH 7/8][next] md/raid5: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2025-02-24 9:53 UTC (permalink / raw)
To: Jens Axboe, Song Liu, Yu Kuai, Carlos Maiolino, Darrick J. Wong,
Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale,
Chris Mason, Josef Bacik, David Sterba, Christoph Hellwig,
Sagi Grimberg, Chaitanya Kulkarni, Coly Li, Kent Overstreet
Cc: linux-raid, linux-kernel, Gustavo A. R. Silva, linux-hardening,
linux-block, linux-xfs, linux-erofs, linux-btrfs, linux-nvme,
linux-bcache
This patch series aims to fix a couple hundred -Wflex-array-member-not-at-end
warnings by creating a new tagged struct `struct bio_hdr` within flexible
structure `struct bio`.
This new tagged struct will be used to fix problematic declarations
of middle-flex-arrays in composite structs, like these[1][2][3], for
instance.
[1] https://git.kernel.org/linus/a7e8997ae18c42d3
[2] https://git.kernel.org/linus/c1ddb29709e675ea
[3] https://git.kernel.org/linus/57be3d3562ca4aa6
Gustavo A. R. Silva (8):
block: blk_types.h: Use struct_group_tagged() in flex struct bio
md/raid5-ppl: Avoid -Wflex-array-member-not-at-end warning
xfs: Avoid -Wflex-array-member-not-at-end warnings
erofs: Avoid -Wflex-array-member-not-at-end warnings
btrfs: Avoid -Wflex-array-member-not-at-end warnings
nvme: target: Avoid -Wflex-array-member-not-at-end warnings
md/raid5: Avoid -Wflex-array-member-not-at-end warnings
bcache: Avoid -Wflex-array-member-not-at-end warnings
drivers/md/bcache/bcache.h | 4 +-
drivers/md/bcache/journal.c | 10 ++--
drivers/md/bcache/journal.h | 4 +-
drivers/md/bcache/super.c | 8 ++--
drivers/md/raid5-ppl.c | 8 ++--
drivers/md/raid5.c | 10 ++--
drivers/md/raid5.h | 2 +-
drivers/nvme/target/nvmet.h | 4 +-
drivers/nvme/target/passthru.c | 2 +-
drivers/nvme/target/zns.c | 2 +-
fs/btrfs/disk-io.c | 4 +-
fs/btrfs/volumes.h | 2 +-
fs/erofs/fileio.c | 25 ++++++----
fs/erofs/fscache.c | 13 +++---
fs/xfs/xfs_log.c | 15 +++---
fs/xfs/xfs_log_priv.h | 2 +-
include/linux/blk_types.h | 84 ++++++++++++++++++----------------
17 files changed, 107 insertions(+), 92 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/8][next] md/raid5-ppl: Avoid -Wflex-array-member-not-at-end warning
2025-02-24 9:53 [PATCH 0/8][next] Avoid a couple hundred -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
@ 2025-02-24 9:56 ` Gustavo A. R. Silva
2025-02-24 10:00 ` [PATCH 7/8][next] md/raid5: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
1 sibling, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2025-02-24 9:56 UTC (permalink / raw)
To: Song Liu, Yu Kuai
Cc: linux-raid, 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.
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 warning:
drivers/md/raid5-ppl.c:153: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>
---
drivers/md/raid5-ppl.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/md/raid5-ppl.c b/drivers/md/raid5-ppl.c
index c0fb335311aa..f4333c644b67 100644
--- a/drivers/md/raid5-ppl.c
+++ b/drivers/md/raid5-ppl.c
@@ -150,7 +150,7 @@ struct ppl_io_unit {
bool submitted; /* true if write to log started */
/* inline bio and its biovec for submitting the iounit */
- struct bio bio;
+ struct bio_hdr bio;
struct bio_vec biovec[PPL_IO_INLINE_BVECS];
};
@@ -250,8 +250,8 @@ static struct ppl_io_unit *ppl_new_iounit(struct ppl_log *log,
INIT_LIST_HEAD(&io->stripe_list);
atomic_set(&io->pending_stripes, 0);
atomic_set(&io->pending_flushes, 0);
- bio_init(&io->bio, log->rdev->bdev, io->biovec, PPL_IO_INLINE_BVECS,
- REQ_OP_WRITE | REQ_FUA);
+ bio_init(container_of(&io->bio, struct bio, __hdr), log->rdev->bdev,
+ io->biovec, PPL_IO_INLINE_BVECS, REQ_OP_WRITE | REQ_FUA);
pplhdr = page_address(io->header_page);
clear_page(pplhdr);
@@ -430,7 +430,7 @@ static void ppl_submit_iounit(struct ppl_io_unit *io)
struct ppl_log *log = io->log;
struct ppl_conf *ppl_conf = log->ppl_conf;
struct ppl_header *pplhdr = page_address(io->header_page);
- struct bio *bio = &io->bio;
+ struct bio *bio = container_of(&io->bio, struct bio, __hdr);
struct stripe_head *sh;
int i;
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 7/8][next] md/raid5: Avoid -Wflex-array-member-not-at-end warnings
2025-02-24 9:53 [PATCH 0/8][next] Avoid a couple hundred -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
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 10:00 ` Gustavo A. R. Silva
1 sibling, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2025-02-24 10:00 UTC (permalink / raw)
To: Song Liu, Yu Kuai
Cc: linux-raid, 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.
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 10 of the following warnings:
drivers/md/raid5.h:262:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/md/raid5.h:262:38: 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/raid5.c | 10 +++++-----
drivers/md/raid5.h | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 5c79429acc64..76981d8cbc5d 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -1178,8 +1178,8 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
again:
dev = &sh->dev[i];
- bi = &dev->req;
- rbi = &dev->rreq; /* For writing to replacement */
+ bi = container_of(&dev->req, struct bio, __hdr);
+ rbi = container_of(&dev->rreq, struct bio, __hdr); /* For writing to replacement */
rdev = conf->disks[i].rdev;
rrdev = conf->disks[i].replacement;
@@ -2720,7 +2720,7 @@ static void raid5_end_read_request(struct bio * bi)
sector_t s;
for (i=0 ; i<disks; i++)
- if (bi == &sh->dev[i].req)
+ if (bi == container_of(&sh->dev[i].req, struct bio, __hdr))
break;
pr_debug("end_read_request %llu/%d, count: %d, error %d.\n",
@@ -2848,11 +2848,11 @@ static void raid5_end_write_request(struct bio *bi)
int replacement = 0;
for (i = 0 ; i < disks; i++) {
- if (bi == &sh->dev[i].req) {
+ if (bi == container_of(&sh->dev[i].req, struct bio, __hdr)) {
rdev = conf->disks[i].rdev;
break;
}
- if (bi == &sh->dev[i].rreq) {
+ if (bi == container_of(&sh->dev[i].rreq, struct bio, __hdr)) {
rdev = conf->disks[i].replacement;
if (rdev)
replacement = 1;
diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h
index eafc6e9ed6ee..3df59302e953 100644
--- a/drivers/md/raid5.h
+++ b/drivers/md/raid5.h
@@ -259,7 +259,7 @@ struct stripe_head {
/* rreq and rvec are used for the replacement device when
* writing data to both devices.
*/
- struct bio req, rreq;
+ struct bio_hdr req, rreq;
struct bio_vec vec, rvec;
struct page *page, *orig_page;
unsigned int offset; /* offset of the page */
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-24 10:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-24 9:53 [PATCH 0/8][next] Avoid a couple hundred -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
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 10:00 ` [PATCH 7/8][next] md/raid5: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).