[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZgVKiK2A+of/+vGr@gondor.apana.org.au>
Date: Thu, 28 Mar 2024 18:46:32 +0800
From: Herbert Xu <herbert@...dor.apana.org.au>
To: "Gustavo A. R. Silva" <gustavoars@...nel.org>
Cc: Haren Myneni <haren@...ibm.com>, Michael Ellerman <mpe@...erman.id.au>,
Nicholas Piggin <npiggin@...il.com>,
Christophe Leroy <christophe.leroy@...roup.eu>,
"Aneesh Kumar K.V" <aneesh.kumar@...nel.org>,
"Naveen N. Rao" <naveen.n.rao@...ux.ibm.com>,
"David S. Miller" <davem@...emloft.net>,
linuxppc-dev@...ts.ozlabs.org, linux-crypto@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org,
Kees Cook <keescook@...omium.org>
Subject: Re: [PATCH][next] crypto/nx: Avoid -Wflex-array-member-not-at-end
warning
On Tue, Mar 05, 2024 at 01:57:56PM -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. So, we are deprecating flexible-array
> members in the middle of another structure.
>
> There is currently an object (`header`) in `struct nx842_crypto_ctx`
> that contains a flexible structure (`struct nx842_crypto_header`):
>
> struct nx842_crypto_ctx {
> ...
> struct nx842_crypto_header header;
> struct nx842_crypto_header_group group[NX842_CRYPTO_GROUP_MAX];
> ...
> };
>
> So, in order to avoid ending up with a flexible-array member in the
> middle of another struct, we use the `struct_group_tagged()` helper to
> separate the flexible array from the rest of the members in the flexible
> structure:
>
> struct nx842_crypto_header {
> struct_group_tagged(nx842_crypto_header_hdr, hdr,
>
> ... the rest of the members
>
> );
> struct nx842_crypto_header_group group[];
> } __packed;
>
> With the change described above, we can now declare an object of the
> type of the tagged struct, without embedding the flexible array in the
> middle of another struct:
>
> struct nx842_crypto_ctx {
> ...
> struct nx842_crypto_header_hdr header;
> struct nx842_crypto_header_group group[NX842_CRYPTO_GROUP_MAX];
> ...
> } __packed;
>
> We also use `container_of()` whenever we need to retrieve a pointer to
> the flexible structure, through which we can access the flexible
> array if needed.
>
> So, with these changes, fix the following warning:
>
> In file included from drivers/crypto/nx/nx-842.c:55:
> drivers/crypto/nx/nx-842.h:174:36: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> 174 | struct nx842_crypto_header header;
> | ^~~~~~
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@...nel.org>
> ---
> drivers/crypto/nx/nx-842.c | 6 ++++--
> drivers/crypto/nx/nx-842.h | 10 ++++++----
> 2 files changed, 10 insertions(+), 6 deletions(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@...dor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Powered by blists - more mailing lists