Commit 1e6b251c authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by Herbert Xu
Browse files

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;
      |                                    ^~~~~~

Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 7467147e
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -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 */
+6 −4
Original line number Diff line number Diff line
@@ -157,9 +157,11 @@ struct nx842_crypto_header_group {
} __packed;

struct nx842_crypto_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;