From: Leon Romanovsky <leon@kernel.org>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] RDMA/cm: Avoid -Wflex-array-member-not-at-end warning
Date: Tue, 2 Apr 2024 11:38:34 +0300 [thread overview]
Message-ID: <20240402083834.GF11187@unreal> (raw)
In-Reply-To: <5c0bb827-e5f3-4178-ad46-8ac9b99d7726@embeddedor.com>
On Mon, Mar 25, 2024 at 08:57:08PM -0600, Gustavo A. R. Silva wrote:
>
>
> On 3/25/24 16:47, Jason Gunthorpe wrote:
> > On Mon, Mar 25, 2024 at 02:24:07PM -0600, Gustavo A. R. Silva wrote:
> > > -Wflex-array-member-not-at-end is coming in GCC-14, and we are getting
> > > ready to enable it globally.
> > >
> > > Use the `struct_group_tagged()` helper to separate the flexible array
> > > from the rest of the members in flexible `struct cm_work`, and avoid
> > > embedding the flexible-array member in `struct cm_timewait_info`.
> > >
> > > Also, use `container_of()` to retrieve a pointer to the flexible
> > > structure.
> > >
> > > So, with these changes, fix the following warning:
> > > drivers/infiniband/core/cm.c:196:24: 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/infiniband/core/cm.c | 21 ++++++++++++---------
> > > 1 file changed, 12 insertions(+), 9 deletions(-)
> > >
> > > diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
> > > index bf0df6ee4f78..80c87085499c 100644
> > > --- a/drivers/infiniband/core/cm.c
> > > +++ b/drivers/infiniband/core/cm.c
> > > @@ -182,18 +182,21 @@ struct cm_av {
> > > };
> > > struct cm_work {
> > > - struct delayed_work work;
> > > - struct list_head list;
> > > - struct cm_port *port;
> > > - struct ib_mad_recv_wc *mad_recv_wc; /* Received MADs */
> > > - __be32 local_id; /* Established / timewait */
> > > - __be32 remote_id;
> > > - struct ib_cm_event cm_event;
> > > + /* New members must be added within the struct_group() macro below. */
> > > + struct_group_tagged(cm_work_hdr, hdr,
> > > + struct delayed_work work;
> > > + struct list_head list;
> > > + struct cm_port *port;
> > > + struct ib_mad_recv_wc *mad_recv_wc; /* Received MADs */
> > > + __be32 local_id; /* Established / timewait */
> > > + __be32 remote_id;
> > > + struct ib_cm_event cm_event;
> > > + );
> > > struct sa_path_rec path[];
> > > };
> >
> > I didn't look, but does it make more sense to break out the path side
> > into its own type and avoid the struct_group_tagged? I seem to
> > remember only one thing used it.
> >
>
> I thought about that, but I'd have to change the parameter type of
> `static int cm_timewait_handler(struct cm_work *work)`, and that would
> imply also modifying the internals of function `cm_work_handler()` (and
> then I didn't look much into it).
So let's try to invest in this direction first before we add obfuscation
with magic words to the code.
Thanks
> So, the `struct_group_tagged()` strategy is in general more cleaner and straightforward.
>
> --
> Gustavo
>
>
prev parent reply other threads:[~2024-04-02 8:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-25 20:24 [PATCH][next] RDMA/cm: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2024-03-25 22:47 ` Jason Gunthorpe
2024-03-26 2:57 ` Gustavo A. R. Silva
2024-04-02 8:38 ` Leon Romanovsky [this message]
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=20240402083834.GF11187@unreal \
--to=leon@kernel.org \
--cc=gustavo@embeddedor.com \
--cc=gustavoars@kernel.org \
--cc=jgg@ziepe.ca \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).