]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KEYS: Avoid -Wflex-array-member-not-at-end warning
authorGustavo A. R. Silva <gustavoars@kernel.org>
Mon, 10 Nov 2025 10:46:45 +0000 (19:46 +0900)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 22 Nov 2025 02:04:50 +0000 (10:04 +0800)
-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/asymmetric_keys/restrict.c:20:34: 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 unsigned char data[10]; onto the FAM
struct asymmetric_key_id::data[], 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.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Ignat Korchagin <ignat@cloudflare.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/asymmetric_keys/restrict.c

index afcd4d101ac5504ef93ed602edafc5f074b2becd..86292965f4930cef34ccbfae13e66cfeeb2327ea 100644 (file)
@@ -17,9 +17,12 @@ static struct asymmetric_key_id *ca_keyid;
 
 #ifndef MODULE
 static struct {
-       struct asymmetric_key_id id;
-       unsigned char data[10];
+       /* Must be last as it ends in a flexible-array member. */
+       TRAILING_OVERLAP(struct asymmetric_key_id, id, data,
+               unsigned char data[10];
+       );
 } cakey;
+static_assert(offsetof(typeof(cakey), id.data) == offsetof(typeof(cakey), data));
 
 static int __init ca_keys_setup(char *str)
 {