DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net/bnxt: fix compiler warnings
@ 2026-10-05 20:25 Manish Kurup
  0 siblings, 0 replies; only message in thread
From: Manish Kurup @ 2026-10-05 20:25 UTC (permalink / raw)
  To: dev; +Cc: kishore.padmanabha, Dakota Sicher

From: Dakota Sicher <dakota.sicher@broadcom.com>

Fix a compiler warning in bnxt_tf_pmd_shim for comparison of
differently signed values. Fix compiler warnings for array
out-of-bounds in ulp_bs_pull_lsb and ulp_bs_pull_msb.

Fixes: 1993b267dbcb ("net/bnxt: cleanup ULP parser and mapper")

Signed-off-by: Dakota Sicher <dakota.sicher@broadcom.com>
Signed-off-by: Manish Kurup <manish.kurup@broadcom.com>
---
 drivers/net/bnxt/tf_ulp/bnxt_tf_pmd_shim.c | 14 +++++++++++---
 drivers/net/bnxt/tf_ulp/ulp_utils.h        | 14 +++++++-------
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/drivers/net/bnxt/tf_ulp/bnxt_tf_pmd_shim.c b/drivers/net/bnxt/tf_ulp/bnxt_tf_pmd_shim.c
index bfd5f4b230..9a7b9bfe34 100644
--- a/drivers/net/bnxt/tf_ulp/bnxt_tf_pmd_shim.c
+++ b/drivers/net/bnxt/tf_ulp/bnxt_tf_pmd_shim.c
@@ -140,10 +140,14 @@ static int32_t ulp_pmd_get_mac_by_pci(const char *pci_name, uint8_t *mac)
 	glob_t gres;
 	FILE *fp;
 	int32_t rc = -EINVAL;
+	int32_t pr;
 
 	memset(path, 0, sizeof(path));
-	sprintf(path, PARENT_PHY_INTF_PATH, pci_name);
-
+	pr = snprintf(path, sizeof(path), PARENT_PHY_INTF_PATH, pci_name);
+	if (unlikely((size_t)pr >= sizeof(path) || pr < 0)) {
+		BNXT_DRV_DBG(ERR, "Error writing path: %s", path);
+		return rc;
+	}
 	/* There can be only one, no more, no less */
 	if (glob(path, 0, glob_error_fn, &gres) == 0) {
 		if (gres.gl_pathc != 1)
@@ -151,7 +155,11 @@ static int32_t ulp_pmd_get_mac_by_pci(const char *pci_name, uint8_t *mac)
 
 		/* Replace the PCI address with interface name and get index */
 		intf_name = basename(gres.gl_pathv[0]);
-		sprintf(path, ULP_PRT_MAC_PATH, pci_name, intf_name);
+		pr = snprintf(path, sizeof(path), ULP_PRT_MAC_PATH, pci_name, intf_name);
+		if (unlikely((size_t)pr >= sizeof(path) || pr < 0)) {
+			BNXT_DRV_DBG(ERR, "Error writing path: %s", path);
+			return rc;
+		}
 
 		fp = fopen(path, "r");
 		if (!fp) {
diff --git a/drivers/net/bnxt/tf_ulp/ulp_utils.h b/drivers/net/bnxt/tf_ulp/ulp_utils.h
index ce20f1916f..354217abc6 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_utils.h
+++ b/drivers/net/bnxt/tf_ulp/ulp_utils.h
@@ -699,18 +699,18 @@ ulp_bs_pull_lsb(uint8_t *src, uint8_t *dst, uint32_t size,
 {
 	uint32_t idx;
 	uint32_t cnt = ULP_BITS_2_BYTE_NR(len);
+	uint32_t rem = len % ULP_BLOB_BYTE;
 
 	/* iterate bytewise to get data */
-	for (idx = 0; idx < cnt; idx++) {
+	for (idx = 0; idx < cnt && idx < size; idx++) {
 		ulp_bs_get_lsb(src, offset, ULP_BLOB_BYTE,
 			       &dst[size - 1 - idx]);
 		offset += ULP_BLOB_BYTE;
-		len -= ULP_BLOB_BYTE;
 	}
 
 	/* Extract the last reminder data that is not 8 byte boundary */
-	if (len)
-		ulp_bs_get_lsb(src, offset, len, &dst[size - 1 - idx]);
+	if (rem && idx < size)
+		ulp_bs_get_lsb(src, offset, rem, &dst[size - 1 - idx]);
 }
 
 /*
@@ -764,17 +764,17 @@ ulp_bs_pull_msb(uint8_t *src, uint8_t *dst,
 {
 	uint32_t idx;
 	uint32_t cnt = ULP_BITS_2_BYTE_NR(len);
+	uint32_t rem = len % ULP_BLOB_BYTE;
 
 	/* iterate bytewise to get data */
 	for (idx = 0; idx < cnt; idx++) {
 		ulp_bs_get_msb(src, offset, ULP_BLOB_BYTE, &dst[idx]);
 		offset += ULP_BLOB_BYTE;
-		len -= ULP_BLOB_BYTE;
 	}
 
 	/* Extract the last reminder data that is not 8 byte boundary */
-	if (len)
-		ulp_bs_get_msb(src, offset, len, &dst[idx]);
+	if (rem)
+		ulp_bs_get_msb(src, offset, rem, &dst[idx]);
 }
 
 /*
-- 
2.31.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-05 20:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-05 20:25 [PATCH] net/bnxt: fix compiler warnings Manish Kurup

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox