Message ID | ef7a6920384ab2f8f83c0f630f94edc73cd65997.1739957534.git.gustavoars@kernel.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Avoid a couple hundred -Wflex-array-member-not-at-end warnings | expand |
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.
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
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 {
-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(-)