eth: bnxt: fix one of the W=1 warnings about fortified memcpy()
authorJakub Kicinski <kuba@kernel.org>
Thu, 27 Jul 2023 19:07:25 +0000 (12:07 -0700)
committerJakub Kicinski <kuba@kernel.org>
Fri, 28 Jul 2023 20:47:34 +0000 (13:47 -0700)
Fix a W=1 warning with gcc 13.1:

In function ‘fortify_memcpy_chk’,
    inlined from ‘bnxt_hwrm_queue_cos2bw_cfg’ at drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c:133:3:
include/linux/fortify-string.h:592:25: warning: call to ‘__read_overflow2_field’ declared with attribute warning: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Wattribute-warning]
  592 |                         __read_overflow2_field(q_size_field, size);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The field group is already defined and starts at queue_id:

struct bnxt_cos2bw_cfg {
u8 pad[3];
struct_group_attr(cfg, __packed,
u8 queue_id;
__le32 min_bw;

Reviewed-by: Michael Chan <michael.chan@broadcom.com>
Link: https://lore.kernel.org/r/20230727190726.1859515-2-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c

index caab3d626a2a92a065e586f050a27442b66bea60..31f85f3e23641dcbceb758d88b5418a7dd941f62 100644 (file)
@@ -130,7 +130,7 @@ static int bnxt_hwrm_queue_cos2bw_cfg(struct bnxt *bp, struct ieee_ets *ets,
                                            BW_VALUE_UNIT_PERCENT1_100);
                }
                data = &req->unused_0 + qidx * (sizeof(cos2bw) - 4);
-               memcpy(data, &cos2bw.queue_id, sizeof(cos2bw) - 4);
+               memcpy(data, &cos2bw.cfg, sizeof(cos2bw) - 4);
                if (qidx == 0) {
                        req->queue_id0 = cos2bw.queue_id;
                        req->unused_0 = 0;