crypto: drbg - Avoid -Wflex-array-member-not-at-end warning
PATCH 1/1 crypto: drbg - Avoid -Wflex-array-member-not-at-end warning
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.
Use the new TRAILING_OVERLAP() helper to fix the following warning:
crypto/drbg.c:1445:27: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
This helper creates a union between a flexible-array member (FAM) and a set of MEMBERS that would otherwise follow it.
This overlays the trailing MEMBER char ctx[]; onto the FAM struct shash_desc::__ctx,[] while keeping the FAM and the start of MEMBER aligned.
The static_assert() ensures this alignment remains, and it's intentionally placed inmediately after the corresponding structures --no blank line in between.
--- crypto/drbg.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
crypto/drbg.c +5 -2
@@ -1442,9 +1442,12 @@ static void drbg_kcapi_set_entropy(struct crypto_rng *tfm,#if defined(CONFIG_CRYPTO_DRBG_HASH ) || defined(CONFIG_CRYPTO_DRBG_HMAC )struct sdesc { -struct shash_desc shash; -char ctx[]; +/* Must be last as it ends in a flexible-array member. */ + TRAILING_OVERLAP(struct shash_desc, shash, __ctx, + char ctx[]; + ); }; +static_assert(offsetof(struct sdesc, shash.__ctx) == offsetof(struct sdesc, ctx));static int drbg_init_hash_kernel (struct drbg_state *drbg) {
Signature · 1 line
2.43.0
Herbert Xu
maintainerPATCH v2 1/1 crypto: drbg - Delete unused ctx from struct sdesc
Quoted 7 lines · Gustavo A. R. Silva
crypto/drbg.c +0
-0@@ -1442,9 +1442,12 @@ static void drbg_kcapi_set_entropy(struct crypto_rng *tfm,
crypto/drbg.c static void drbg_kcapi_set_entropy(struct crypto_rng *tfm, · line 1450
Quoted 10 lines
crypto/drbg.c +5
-2#if defined(CONFIG_CRYPTO_DRBG_HASH ) || defined(CONFIG_CRYPTO_DRBG_HMAC )struct sdesc { -struct shash_desc shash; -char ctx[]; +/* Must be last as it ends in a flexible-array member. */ + TRAILING_OVERLAP(struct shash_desc, shash, __ctx, + char ctx[]; + ); }; +static_assert(offsetof(struct sdesc, shash.__ctx) == offsetof(struct sdesc, ctx));
This isn't even used. Just delete it:
---8<---
The ctx array in struct sdesc is never used. Delete it as it's bogus since the previous member ends with a flexible array.
crypto/drbg.c +0 -1
@@ -1443,7 +1443,6 @@ static void drbg_kcapi_set_entropy(struct crypto_rng *tfm,#if defined(CONFIG_CRYPTO_DRBG_HASH ) || defined(CONFIG_CRYPTO_DRBG_HMAC )struct sdesc {struct shash_desc shash; -char ctx[]; };static int drbg_init_hash_kernel (struct drbg_state *drbg)
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [v2 PATCH] crypto: drbg - Delete unused ctx from struct sdesc
Quoted 8 lines · Herbert Xu
Quoted 7 lines · Gustavo A. R. Silva
crypto/drbg.c +0
-0@@ -1442,9 +1442,12 @@ static void drbg_kcapi_set_entropy(struct crypto_rng *tfm,
Quoted 12 lines
crypto/drbg.c static void drbg_kcapi_set_entropy(struct crypto_rng *tfm, · line 1450
Quoted 10 lines
crypto/drbg.c +5
-2#if defined(CONFIG_CRYPTO_DRBG_HASH ) || defined(CONFIG_CRYPTO_DRBG_HMAC )struct sdesc { -struct shash_desc shash; -char ctx[]; +/* Must be last as it ends in a flexible-array member. */ + TRAILING_OVERLAP(struct shash_desc, shash, __ctx, + char ctx[]; + ); }; +static_assert(offsetof(struct sdesc, shash.__ctx) == offsetof(struct sdesc, ctx));This isn't even used. Just delete it:
Awesome. :)
Thanks!
-Gustavo
Quoted 20 lines
---8<---
The ctx array in struct sdesc is never used. Delete it as it's bogus since the previous member ends with a flexible array.Reported-by Gustavo A. R. Silva <[email protected]>Signed-off-by Herbert Xu <[email protected]>crypto/drbg.c +0
-1@@ -1443,7 +1443,6 @@ static void drbg_kcapi_set_entropy(struct crypto_rng *tfm,#if defined(CONFIG_CRYPTO_DRBG_HASH ) || defined(CONFIG_CRYPTO_DRBG_HMAC )struct sdesc {struct shash_desc shash; -char ctx[]; };static int drbg_init_hash_kernel (struct drbg_state *drbg)