crypto/nx: Avoid -Wflex-array-member-not-at-end warning
Subsystems (3)
PATCH 1/1 crypto/nx: Avoid -Wflex-array-member-not-at-end warning
-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;
| ^~~~~~
--- drivers/crypto/nx/nx-842.c | 6 ++++-- drivers/crypto/nx/nx-842.h | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-)
drivers/crypto/nx/nx-842.c +4 -2
@@ -251,7 +251,9 @@ int nx842_crypto_compress(struct crypto_tfm *tfm, u8 *dst, unsigned int *dlen) { struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm); -struct nx842_crypto_header *hdr = &ctx->header; +struct nx842_crypto_header *hdr = +container_of (&ctx->header, + struct nx842_crypto_header, hdr);struct nx842_crypto_param p;struct nx842_constraints c = *ctx->driver->constraints;unsigned int groups, hdrsize, h;
@@ -490,7 +492,7 @@ int nx842_crypto_decompress(struct crypto_tfm *tfm, }memcpy (&ctx->header, src, hdr_len); - hdr = &ctx->header; + hdr = container_of(&ctx->header, struct nx842_crypto_header, hdr);for (n =0 ; n < hdr->groups; n++) {/* ignore applies to last group */
drivers/crypto/nx/nx-842.h +6 -4
@@ -157,9 +157,11 @@ struct nx842_crypto_header_group { } __packed;struct nx842_crypto_header { -__be16 magic;/* NX842_CRYPTO_MAGIC */ -__be16 ignore;/* decompressed end bytes to ignore */ -u8 groups;/* total groups in this header */ + struct_group_tagged(nx842_crypto_header_hdr, hdr, + __be16 magic; /* NX842_CRYPTO_MAGIC */ +__be16 ignore;/* decompressed end bytes to ignore */ +u8 groups;/* total groups in this header */ + );struct nx842_crypto_header_group group[]; } __packed;
@@ -171,7 +173,7 @@ struct nx842_crypto_ctx {u8 *wmem;u8 *sbounce, *dbounce; -struct nx842_crypto_header header; +struct nx842_crypto_header_hdr header;struct nx842_crypto_header_group group[NX842_CRYPTO_GROUP_MAX ];struct nx842_driver *driver;
Signature · 1 line
2.34.1
Herbert Xu
maintainerQuoted 50 lines · Gustavo A. R. Silva
-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) instruct nx842_crypto_ctxthat 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 | structnx842_crypto_headerheader;
| ^~~~~~
Quoted 5 lines
Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/crypto/nx/nx-842.c | 6 ++++-- drivers/crypto/nx/nx-842.h | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-)
Patch applied. Thanks.
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