From: Simon Horman <horms@kernel.org>
To: Ankit Khushwaha <ankitkhushwaha.linux@gmail.com>
Cc: Steffen Klassert <steffen.klassert@secunet.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Shuah Khan <shuah@kernel.org>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
Jason Xing <kernelxing@tencent.com>,
netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-kernel-mentees@lists.linuxfoundation.org
Subject: Re: [PATCH] selftest: net: fix variable sized type not at the end of struct warnings
Date: Tue, 11 Nov 2025 14:55:58 +0000 [thread overview]
Message-ID: <aRNOfir6X9FmaUrd@horms.kernel.org> (raw)
In-Reply-To: <aQ9-F34aW__rlMuD@fedora>
On Sat, Nov 08, 2025 at 10:59:59PM +0530, Ankit Khushwaha wrote:
> On Tue, Oct 28, 2025 at 05:23:12PM +0000, Simon Horman wrote:
> > On Mon, Oct 27, 2025 at 10:38:56AM +0530, Ankit Khushwaha wrote:
> > > Some network selftests defined variable-sized types defined at the end of
> > > struct causing -Wgnu-variable-sized-type-not-at-end warning.
> > >
> > > warning:
> > > timestamping.c:285:18: warning: field 'cm' with variable sized type
> > > 'struct cmsghdr' not at the end of a struct or class is a GNU
> > > extension [-Wgnu-variable-sized-type-not-at-end]
> > > 285 | struct cmsghdr cm;
> > > | ^
> > >
> > > ipsec.c:835:5: warning: field 'u' with variable sized type 'union
> > > (unnamed union at ipsec.c:831:3)' not at the end of a struct or class
> > > is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
> > > 835 | } u;
> > > | ^
> > >
> > > This patch move these field at the end of struct to fix these warnings.
> > >
> > > Signed-off-by: Ankit Khushwaha <ankitkhushwaha.linux@gmail.com>
> >
> > Hi Ankit,
> >
> > I don't believe this change is correct.
> >
> > I think that the intention of the code is the char arrays (buf and control)
> > provide the buffer space for the variable-length trailing field
> > of the preceding structure. Where we basically have a header followed
> > by data. But your patch would place the before the header.
> >
> Hi Simon,
> So if buf and control providing the buffer space, then i think it is
> better to suppress `-Wgnu-variable-sized-type-not-at-end` warning
> within this block of code.
>
> #pragma GCC diagnostic push
> #pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
I'm unsure of the attitude towards using #pragma like this in kernel code,
but certainly it would be a new one for me.
>
> struct {
> union {
> struct xfrm_algo alg;
> struct xfrm_algo_aead aead;
> struct xfrm_algo_auth auth;
> } u;
> char buf[XFRM_ALGO_KEY_BUF_SIZE];
> } alg = {};
>
> #pragma GCC diagnostic pop
>
> I think this would be fine.
In my view, the most promising approach I am aware of is using
TRAILING_OVERLAP(), as illustrated in [1]. However, that
approach was recently rejected, so I guess that means
it doesn't have much promise after all.
[1] https://lore.kernel.org/netdev/aPdx4iPK4-KIhjFq@kspp/
prev parent reply other threads:[~2025-11-11 14:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-27 5:08 [PATCH] selftest: net: fix variable sized type not at the end of struct warnings Ankit Khushwaha
2025-10-28 17:23 ` Simon Horman
2025-11-08 17:29 ` Ankit Khushwaha
2025-11-11 14:55 ` Simon Horman [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=aRNOfir6X9FmaUrd@horms.kernel.org \
--to=horms@kernel.org \
--cc=ankitkhushwaha.linux@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=kernelxing@tencent.com \
--cc=kuba@kernel.org \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=steffen.klassert@secunet.com \
--cc=willemdebruijn.kernel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.