Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KEYS: 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/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>

authored by

Gustavo A. R. Silva and committed by
Herbert Xu
a26c23e0 8700ce07

+5 -2
+5 -2
crypto/asymmetric_keys/restrict.c
··· 17 17 18 18 #ifndef MODULE 19 19 static struct { 20 - struct asymmetric_key_id id; 21 - unsigned char data[10]; 20 + /* Must be last as it ends in a flexible-array member. */ 21 + TRAILING_OVERLAP(struct asymmetric_key_id, id, data, 22 + unsigned char data[10]; 23 + ); 22 24 } cakey; 25 + static_assert(offsetof(typeof(cakey), id.data) == offsetof(typeof(cakey), data)); 23 26 24 27 static int __init ca_keys_setup(char *str) 25 28 {