Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [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 10:00 ` [PATCH 6/8][next] nvme: target: Avoid " Gustavo A. R. Silva
  0 siblings, 1 reply; 4+ 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] 4+ messages in thread

* [PATCH 6/8][next] nvme: target: 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 10:00 ` Gustavo A. R. Silva
  2025-02-24 14:19   ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2025-02-24 10:00 UTC (permalink / raw)
  To: Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni
  Cc: linux-nvme, 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 38 of the following warnings:

drivers/nvme/target/nvmet.h:455:49: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/nvme/target/nvmet.h:462:49: 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/nvme/target/nvmet.h    | 4 ++--
 drivers/nvme/target/passthru.c | 2 +-
 drivers/nvme/target/zns.c      | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 4be8d22d2d8d..13ee8026d3d8 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -452,14 +452,14 @@ struct nvmet_req {
 			struct work_struct      work;
 		} f;
 		struct {
-			struct bio		inline_bio;
+			struct bio_hdr		inline_bio;
 			struct request		*rq;
 			struct work_struct      work;
 			bool			use_workqueue;
 		} p;
 #ifdef CONFIG_BLK_DEV_ZONED
 		struct {
-			struct bio		inline_bio;
+			struct bio_hdr		inline_bio;
 			struct work_struct	zmgmt_work;
 		} z;
 #endif /* CONFIG_BLK_DEV_ZONED */
diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c
index 26e2907ce8bb..bff52252ffb9 100644
--- a/drivers/nvme/target/passthru.c
+++ b/drivers/nvme/target/passthru.c
@@ -268,7 +268,7 @@ static int nvmet_passthru_map_sg(struct nvmet_req *req, struct request *rq)
 		return -EINVAL;
 
 	if (nvmet_use_inline_bvec(req)) {
-		bio = &req->p.inline_bio;
+		bio = container_of(&req->p.inline_bio, struct bio, __hdr);
 		bio_init(bio, NULL, req->inline_bvec,
 			 ARRAY_SIZE(req->inline_bvec), req_op(rq));
 	} else {
diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c
index 29a60fabfcc8..afedbd984d39 100644
--- a/drivers/nvme/target/zns.c
+++ b/drivers/nvme/target/zns.c
@@ -570,7 +570,7 @@ void nvmet_bdev_execute_zone_append(struct nvmet_req *req)
 	}
 
 	if (nvmet_use_inline_bvec(req)) {
-		bio = &req->z.inline_bio;
+		bio = container_of(&req->z.inline_bio, struct bio, __hdr);
 		bio_init(bio, req->ns->bdev, req->inline_bvec,
 			 ARRAY_SIZE(req->inline_bvec), opf);
 	} else {
-- 
2.43.0



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

* Re: [PATCH 6/8][next] nvme: target: Avoid -Wflex-array-member-not-at-end warnings
  2025-02-24 10:00 ` [PATCH 6/8][next] nvme: target: Avoid " Gustavo A. R. Silva
@ 2025-02-24 14:19   ` Christoph Hellwig
  2025-02-25  1:51     ` Gustavo A. R. Silva
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2025-02-24 14:19 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni, linux-nvme,
	linux-kernel, linux-hardening

On Mon, Feb 24, 2025 at 08:30:10PM +1030, Gustavo A. R. Silva wrote:
> -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 38 of the following warnings:
> 
> drivers/nvme/target/nvmet.h:455:49: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> drivers/nvme/target/nvmet.h:462:49: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> 

I'm not sure where you bio_hdr structure comes from, but maybe that's
because you annoyingly split CC over the series, and by the number of
patches probably also bundled unrelated changes.

In general our first resort here should be to move embedded bio to the
of containing structures.  If that's not possible you'll need to explain
why.



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

* Re: [PATCH 6/8][next] nvme: target: Avoid -Wflex-array-member-not-at-end warnings
  2025-02-24 14:19   ` Christoph Hellwig
@ 2025-02-25  1:51     ` Gustavo A. R. Silva
  0 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2025-02-25  1:51 UTC (permalink / raw)
  To: Christoph Hellwig, Gustavo A. R. Silva
  Cc: Sagi Grimberg, Chaitanya Kulkarni, linux-nvme, linux-kernel,
	linux-hardening



On 25/02/25 00:49, Christoph Hellwig wrote:
> On Mon, Feb 24, 2025 at 08:30:10PM +1030, Gustavo A. R. Silva wrote:
>> -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 38 of the following warnings:
>>
>> drivers/nvme/target/nvmet.h:455:49: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
>> drivers/nvme/target/nvmet.h:462:49: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
>>
> 
> I'm not sure where you bio_hdr structure comes from, but maybe that's
> because you annoyingly split CC over the series, and by the number of
> patches probably also bundled unrelated changes.

Ugh, yes, I messed up my script just before creating the series.

> 
> In general our first resort here should be to move embedded bio to the
> of containing structures.  If that's not possible you'll need to explain
> why.
> 

Yes. Also, thanks for the feedback in your other response. I'll try to
follow that approach and see how it goes.

--
Gustavo


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

end of thread, other threads:[~2025-02-25  1:52 UTC | newest]

Thread overview: 4+ 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 10:00 ` [PATCH 6/8][next] nvme: target: Avoid " Gustavo A. R. Silva
2025-02-24 14:19   ` Christoph Hellwig
2025-02-25  1:51     ` 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