crypto: qat - Avoid -Wflex-array-member-not-at-end warnings
authorGustavo A. R. Silva <gustavoars@kernel.org>
Mon, 25 Mar 2024 20:44:55 +0000 (14:44 -0600)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 5 Apr 2024 07:45:59 +0000 (15:45 +0800)
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting
ready to enable it globally.

Use the `__struct_group()` helper to separate the flexible array
from the rest of the members in flexible `struct qat_alg_buf_list`,
through tagged `struct qat_alg_buf_list_hdr`, and avoid embedding the
flexible-array member in the middle of `struct qat_alg_fixed_buf_list`.

Also, use `container_of()` whenever we need to retrieve a pointer to
the flexible structure.

So, with these changes, fix the following warnings:
drivers/crypto/intel/qat/qat_common/qat_bl.h:25:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/crypto/intel/qat/qat_common/qat_bl.h:25:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/crypto/intel/qat/qat_common/qat_bl.h:25:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/crypto/intel/qat/qat_common/qat_bl.h:25:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/crypto/intel/qat/qat_common/qat_bl.h:25:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/crypto/intel/qat/qat_common/qat_bl.h:25:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/crypto/intel/qat/qat_common/qat_bl.h:25:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/crypto/intel/qat/qat_common/qat_bl.h:25:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

Link: https://github.com/KSPP/linux/issues/202
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Acked-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/intel/qat/qat_common/qat_bl.c
drivers/crypto/intel/qat/qat_common/qat_bl.h

index 76baed0a76c0ee9386e9c14b60315026be6b532a..338acf29c487b6784abd04379df282d17309614c 100644 (file)
@@ -81,7 +81,8 @@ static int __qat_bl_sgl_to_bufl(struct adf_accel_dev *accel_dev,
                if (unlikely(!bufl))
                        return -ENOMEM;
        } else {
-               bufl = &buf->sgl_src.sgl_hdr;
+               bufl = container_of(&buf->sgl_src.sgl_hdr,
+                                   struct qat_alg_buf_list, hdr);
                memset(bufl, 0, sizeof(struct qat_alg_buf_list));
                buf->sgl_src_valid = true;
        }
@@ -139,7 +140,8 @@ static int __qat_bl_sgl_to_bufl(struct adf_accel_dev *accel_dev,
                        if (unlikely(!buflout))
                                goto err_in;
                } else {
-                       buflout = &buf->sgl_dst.sgl_hdr;
+                       buflout = container_of(&buf->sgl_dst.sgl_hdr,
+                                              struct qat_alg_buf_list, hdr);
                        memset(buflout, 0, sizeof(struct qat_alg_buf_list));
                        buf->sgl_dst_valid = true;
                }
index d87e4f35ac395c768dd4f57ecf25a85f862c9352..85bc32a9ec0eb32e32ef85f282fcefb53c9f734f 100644 (file)
@@ -15,14 +15,17 @@ struct qat_alg_buf {
 } __packed;
 
 struct qat_alg_buf_list {
-       u64 resrvd;
-       u32 num_bufs;
-       u32 num_mapped_bufs;
+       /* New members must be added within the __struct_group() macro below. */
+       __struct_group(qat_alg_buf_list_hdr, hdr, __packed,
+               u64 resrvd;
+               u32 num_bufs;
+               u32 num_mapped_bufs;
+       );
        struct qat_alg_buf buffers[];
 } __packed;
 
 struct qat_alg_fixed_buf_list {
-       struct qat_alg_buf_list sgl_hdr;
+       struct qat_alg_buf_list_hdr sgl_hdr;
        struct qat_alg_buf descriptors[QAT_MAX_BUFF_DESC];
 } __packed __aligned(64);