Skip to contentSkip to conversation

bnxt_en: Fix 2 compile warnings in bnxt_dcb.c

PATCH Applied Michael Chan 3 participants 6 messages Aug 7, 2023 – Aug 8, 2023

Subsystems (3)
lore
Share & tools
lore

Michael Chan

author maintainer
#0 lore raw

cover bnxt_en: Fix 2 compile warnings in bnxt_dcb.c

Fix 2 similar warnings in bnxt_dcb.c related to the cos2bw interface definitions in bnxt_hsi.h.

Michael Chan (2):
bnxt_en: Fix W=1 warning in bnxt_dcb.c from fortify memcpy()
bnxt_en: Fix W=stringop-overflow warning in bnxt_dcb.c

 drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c |  26 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_hsi.h | 644 +++---------------
 2 files changed, 101 insertions(+), 569 deletions(-)
Signature · 1 line
2.30.1
author maintainer
#1 lore raw

PATCH 1/2 bnxt_en: Fix W=1 warning in bnxt_dcb.c from fortify memcpy()

Fix the following warning:

inlined from ‘bnxt_hwrm_queue_cos2bw_qcfg’ at drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c:165:3,
./include/linux/fortify-string.h:592:4: error: call to ‘__read_overflow2_field’ declared with attribute warning: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Werror]

    __read_overflow2_field(q_size_field, size);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Modify the FW interface defintion of struct hwrm_queue_cos2bw_qcfg_output to use an array of sub struct for the queue1 to queue7 fields. Note that the layout of the queue0 fields are different and these are not part of the array. This makes the code much cleaner by removing the pointer arithmetic for memcpy().

---
 drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c |  15 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_hsi.h | 322 +++---------------
 2 files changed, 52 insertions(+), 285 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c +10 -5
index 31f85f3e2364..052a0821153e 100644
@@ -144,7 +144,6 @@ static int bnxt_hwrm_queue_cos2bw_qcfg(struct bnxt *bp, struct ieee_ets *ets)
 	struct hwrm_queue_cos2bw_qcfg_output *resp;
 	struct hwrm_queue_cos2bw_qcfg_input *req;
 	struct bnxt_cos2bw_cfg cos2bw;
-	void *data;
 	int rc, i;
 
 	rc = hwrm_req_init(bp, req, HWRM_QUEUE_COS2BW_QCFG);
@@ -158,13 +157,19 @@ static int bnxt_hwrm_queue_cos2bw_qcfg(struct bnxt *bp, struct ieee_ets *ets)
 		return rc;
 	}
 
-	data = &resp->queue_id0 + offsetof(struct bnxt_cos2bw_cfg, queue_id);
-	for (i = 0; i < bp->max_tc; i++, data += sizeof(cos2bw.cfg)) {
+	for (i = 0; i < bp->max_tc; i++) {
 		int tc;
 
-		memcpy(&cos2bw.cfg, data, sizeof(cos2bw.cfg));
-		if (i == 0)
+		if (i == 0) {
 			cos2bw.queue_id = resp->queue_id0;
+			cos2bw.min_bw = resp->queue_id0_min_bw;
+			cos2bw.max_bw = resp->queue_id0_max_bw;
+			cos2bw.tsa = resp->queue_id0_tsa_assign;
+			cos2bw.pri_lvl = resp->queue_id0_pri_lvl;
+			cos2bw.bw_weight = resp->queue_id0_bw_weight;
+		} else {
+			memcpy(&cos2bw.cfg, &resp->cfg[i - 1], sizeof(cos2bw.cfg));
+		}
 
 		tc = bnxt_queue_to_tc(bp, cos2bw.queue_id);
 		if (tc < 0)
drivers/net/ethernet/broadcom/bnxt/bnxt_hsi.h +42 -280

328 lines not on this page · raw message

Signature · 1 line
2.30.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH net-next 1/2] bnxt_en: Fix W=1 warning in bnxt_dcb.c from fortify memcpy()

Quoted 4 lines · Michael Chan

Fix the following warning:

inlined from ‘bnxt_hwrm_queue_cos2bw_qcfg’ at drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c:165:3,
./include/linux/fortify-string.h:592:4: error: call to ‘__read_overflow2_field’ declared with attribute warning: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Werror]

Quoted 8 lines
    __read_overflow2_field(q_size_field, size);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Modify the FW interface defintion of struct hwrm_queue_cos2bw_qcfg_output to use an array of sub struct for the queue1 to queue7 fields. Note that the layout of the queue0 fields are different and these are not part of the array. This makes the code much cleaner by removing the pointer arithmetic for memcpy().

Thanks for fixing this. :)

Quoted 4 lines

--
Gustavo

author maintainer
#3 lore raw

PATCH 2/2 bnxt_en: Fix W=stringop-overflow warning in bnxt_dcb.c

In reply to Michael Chan

Fix the following warning:

drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c: In function ‘bnxt_hwrm_queue_cos2bw_cfg’:
cc1: error: writing 12 bytes into a region of size 1 [-Werror=stringop-overflow ]
In file included from drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c:19:
drivers/net/ethernet/broadcom/bnxt/bnxt_hsi.h:6045:17: note: destination object ‘unused_0’ of size 1
6045 | u8 unused_0;

Fix it by modifying struct hwrm_queue_cos2bw_cfg_input to use an array of sub struct similar to the previous patch. This will eliminate the pointer arithmetc to calculate the destination pointer passed to memcpy().

---
 drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c |  11 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_hsi.h | 322 +++---------------
 2 files changed, 49 insertions(+), 284 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c +7 -4
index 052a0821153e..63e067038385 100644
@@ -98,7 +98,6 @@ static int bnxt_hwrm_queue_cos2bw_cfg(struct bnxt *bp, struct ieee_ets *ets,
 {
 	struct hwrm_queue_cos2bw_cfg_input *req;
 	struct bnxt_cos2bw_cfg cos2bw;
-	void *data;
 	int rc, i;
 
 	rc = hwrm_req_init(bp, req, HWRM_QUEUE_COS2BW_CFG);
@@ -129,11 +128,15 @@ static int bnxt_hwrm_queue_cos2bw_cfg(struct bnxt *bp, struct ieee_ets *ets,
 				cpu_to_le32((ets->tc_tx_bw[i] * 100) |
 					    BW_VALUE_UNIT_PERCENT1_100);
 		}
-		data = &req->unused_0 + qidx * (sizeof(cos2bw) - 4);
-		memcpy(data, &cos2bw.cfg, sizeof(cos2bw) - 4);
 		if (qidx == 0) {
 			req->queue_id0 = cos2bw.queue_id;
-			req->unused_0 = 0;
+			req->queue_id0_min_bw = cos2bw.min_bw;
+			req->queue_id0_max_bw = cos2bw.max_bw;
+			req->queue_id0_tsa_assign = cos2bw.tsa;
+			req->queue_id0_pri_lvl = cos2bw.pri_lvl;
+			req->queue_id0_bw_weight = cos2bw.bw_weight;
+		} else {
+			memcpy(&req->cfg[i - 1], &cos2bw.cfg, sizeof(cos2bw.cfg));
 		}
 	}
 	return hwrm_req_send(bp, req);
drivers/net/ethernet/broadcom/bnxt/bnxt_hsi.h +42 -280

328 lines not on this page · raw message

Signature · 1 line
2.30.1
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH net-next 2/2] bnxt_en: Fix W=stringop-overflow warning in bnxt_dcb.c

Quoted 8 lines · Michael Chan

Fix the following warning:

drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c: In function ‘bnxt_hwrm_queue_cos2bw_cfg’:
cc1: error: writing 12 bytes into a region of size 1 [-Werror=stringop-overflow ]
In file included from drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c:19:
drivers/net/ethernet/broadcom/bnxt/bnxt_hsi.h:6045:17: note: destination object ‘unused_0’ of size 1
6045 | u8 unused_0;

Quoted 4 lines

Fix it by modifying struct hwrm_queue_cos2bw_cfg_input to use an array of sub struct similar to the previous patch. This will eliminate the pointer arithmetc to calculate the destination pointer passed to memcpy().

Thanks for fixing this. :)

Quoted 3 lines

--
Gustavo

#5 lore raw
In reply to Michael Chan
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Mon, 7 Aug 2023 07:57:18 -0700 you wrote:

Fix 2 similar warnings in bnxt_dcb.c related to the cos2bw interface definitions in bnxt_hsi.h.

Michael Chan (2):
bnxt_en: Fix W=1 warning in bnxt_dcb.c from fortify memcpy()
bnxt_en: Fix W=stringop-overflow warning in bnxt_dcb.c

[...]

Here is the summary with links:
- [net-next,1/2] bnxt_en: Fix W=1 warning in bnxt_dcb.c from fortify memcpy()

    https://git.kernel.org/netdev/net-next/c/ac1b8c978a7a
  - [net-next,2/2] bnxt_en: Fix W=stringop-overflow warning in bnxt_dcb.c
    https://git.kernel.org/netdev/net-next/c/3d5ecada049f

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html