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

Configure Feed

Select the types of activity you want to include in your feed.

crypto: nx - Use static_assert() to check struct sizes

Commit 1e6b251ce175 ("crypto: nx - Avoid -Wflex-array-member-not-at-end
warning") introduced tagged `struct nx842_crypto_header_hdr`. We want
to ensure that when new members need to be added to the flexible
structure, they are always included within this tagged struct.

So, we use `static_assert()` to ensure that the memory layout for
both the flexible structure and the tagged struct is the same after
any changes.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Gustavo A. R. Silva and committed by
Herbert Xu
f2f853e7 8caa061c

+3
+3
drivers/crypto/nx/nx-842.h
··· 157 157 } __packed; 158 158 159 159 struct nx842_crypto_header { 160 + /* New members MUST be added within the struct_group() macro below. */ 160 161 struct_group_tagged(nx842_crypto_header_hdr, hdr, 161 162 __be16 magic; /* NX842_CRYPTO_MAGIC */ 162 163 __be16 ignore; /* decompressed end bytes to ignore */ ··· 165 164 ); 166 165 struct nx842_crypto_header_group group[]; 167 166 } __packed; 167 + static_assert(offsetof(struct nx842_crypto_header, group) == sizeof(struct nx842_crypto_header_hdr), 168 + "struct member likely outside of struct_group_tagged()"); 168 169 169 170 #define NX842_CRYPTO_GROUP_MAX (0x20) 170 171