[v2,5/5] net/bnxt/tf_ulp: fix coverity errors

Message ID 20241119054550.1255359-6-sriharsha.basavapatna@broadcom.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ajit Khaparde
Headers
Series TruFlow fixes for Thor2 |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing warning Testing issues
ci/iol-sample-apps-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS

Commit Message

Sriharsha Basavapatna Nov. 19, 2024, 5:45 a.m. UTC
From: Peter Spreadborough <peter.spreadborough@broadcom.com>

This patch fixes a few coverity errors reported in the feature
patchset (merged) to support TruFlow on Thor2.

Fixes: 0513f0af034d ("net/bnxt/tf_ulp: add stats cache for Thor2")
Signed-off-by: Peter Spreadborough <peter.spreadborough@broadcom.com>
Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
---
 drivers/net/bnxt/hcapi/cfa_v3/mm/cfa_mm.c   |  6 +++++-
 drivers/net/bnxt/tf_core/v3/tfc_em.c        |  1 +
 drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c |  2 +-
 drivers/net/bnxt/tf_ulp/bnxt_ulp_utils.h    |  3 ++-
 drivers/net/bnxt/tf_ulp/ulp_mapper.c        | 10 +++++++---
 drivers/net/bnxt/tf_ulp/ulp_rte_parser.c    |  7 ++++++-
 drivers/net/bnxt/tf_ulp/ulp_sc_mgr.c        |  2 ++
 7 files changed, 24 insertions(+), 7 deletions(-)
  

Patch

diff --git a/drivers/net/bnxt/hcapi/cfa_v3/mm/cfa_mm.c b/drivers/net/bnxt/hcapi/cfa_v3/mm/cfa_mm.c
index 61fafadb20..05528dd3e4 100644
--- a/drivers/net/bnxt/hcapi/cfa_v3/mm/cfa_mm.c
+++ b/drivers/net/bnxt/hcapi/cfa_v3/mm/cfa_mm.c
@@ -123,7 +123,11 @@  int cfa_mm_open(void *cmm, struct cfa_mm_open_parms *parms)
 	}
 
 	for (i = 0; i < num_blocks; i++) {
-		context->blk_tbl[i].prev_blk_idx = i - 1;
+		if (i == 0)
+			context->blk_tbl[i].prev_blk_idx = CFA_MM_INVALID32;
+		else
+			context->blk_tbl[i].prev_blk_idx = i - 1;
+
 		context->blk_tbl[i].next_blk_idx = i + 1;
 		context->blk_tbl[i].num_free_records = records_per_block;
 		context->blk_tbl[i].first_free_record = 0;
diff --git a/drivers/net/bnxt/tf_core/v3/tfc_em.c b/drivers/net/bnxt/tf_core/v3/tfc_em.c
index a70e35b6b1..d460ff2ee0 100644
--- a/drivers/net/bnxt/tf_core/v3/tfc_em.c
+++ b/drivers/net/bnxt/tf_core/v3/tfc_em.c
@@ -560,6 +560,7 @@  int tfc_em_delete_raw(struct tfc *tfcp,
 	mpc_msg_out.cmp_type = CMPL_BASE_TYPE_MID_PATH_LONG;
 	mpc_msg_out.msg_data = &rx_msg[TFC_MPC_HEADER_SIZE_BYTES];
 	mpc_msg_out.msg_size = TFC_MPC_MAX_RX_BYTES;
+	mpc_msg_out.chnl_id = 0;
 
 	rc = tfc_mpc_send(tfcp->bp,
 			  &mpc_msg_in,
diff --git a/drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c b/drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c
index 1770069295..c29933b803 100644
--- a/drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c
+++ b/drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c
@@ -468,7 +468,7 @@  static int alloc_link_pbl(struct tfc_ts_mem_cfg *mem_cfg, uint32_t page_size,
 	 * and page tables. The allocation will occur once only per backing
 	 * store and will located by name and reused on subsequent runs.
 	 */
-	total_size = page_size * total_pages;
+	total_size = (uint64_t)page_size * (uint64_t)total_pages;
 
 	if (total_size <= (1024 * 256))
 		mz_size = RTE_MEMZONE_256KB;
diff --git a/drivers/net/bnxt/tf_ulp/bnxt_ulp_utils.h b/drivers/net/bnxt/tf_ulp/bnxt_ulp_utils.h
index 5e0d906fbd..e849df2713 100644
--- a/drivers/net/bnxt/tf_ulp/bnxt_ulp_utils.h
+++ b/drivers/net/bnxt/tf_ulp/bnxt_ulp_utils.h
@@ -1084,8 +1084,9 @@  bnxt_ulp_cap_feat_process(uint64_t feat_bits, uint64_t *out_bits)
 
 	if (bit & BNXT_ULP_FEATURE_BIT_PARENT_DMAC)
 		BNXT_DRV_DBG(ERR, "Parent Mac Address Feature is enabled\n");
-	if (bit & BNXT_ULP_FEATURE_BIT_PORT_DMAC)
+	else if (bit & BNXT_ULP_FEATURE_BIT_PORT_DMAC)
 		BNXT_DRV_DBG(ERR, "Port Mac Address Feature is enabled\n");
+
 	if (bit & BNXT_ULP_FEATURE_BIT_MULTI_TUNNEL_FLOW)
 		BNXT_DRV_DBG(ERR, "Multi Tunnel Flow Feature is enabled\n");
 
diff --git a/drivers/net/bnxt/tf_ulp/ulp_mapper.c b/drivers/net/bnxt/tf_ulp/ulp_mapper.c
index 2429ac2f1a..1a68cf5dfd 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_mapper.c
+++ b/drivers/net/bnxt/tf_ulp/ulp_mapper.c
@@ -3612,9 +3612,13 @@  ulp_mapper_func_cond_list_process(struct bnxt_ulp_mapper_parms *parms,
 		}
 	}
 	/* write the value into result */
-	ulp_operand_read(val, res_local + res_size -
-			 ULP_BITS_2_BYTE_NR(oper_size),
-			 ULP_BITS_2_BYTE_NR(val_len));
+	if (unlikely(ulp_operand_read(val, res_local + res_size -
+				      ULP_BITS_2_BYTE_NR(oper_size),
+				      ULP_BITS_2_BYTE_NR(val_len)))) {
+		BNXT_DRV_DBG(ERR,
+			     "field idx operand read failed\n");
+		return -EINVAL;
+	}
 
 	/* convert the data to cpu format */
 	*res = tfp_be_to_cpu_64(*res);
diff --git a/drivers/net/bnxt/tf_ulp/ulp_rte_parser.c b/drivers/net/bnxt/tf_ulp/ulp_rte_parser.c
index dd5985cd7b..f75606ca81 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_rte_parser.c
+++ b/drivers/net/bnxt/tf_ulp/ulp_rte_parser.c
@@ -517,7 +517,12 @@  ulp_rte_parser_svif_set(struct ulp_rte_parser_params *params,
 		else
 			svif_type = BNXT_ULP_DRV_FUNC_SVIF;
 	}
-	ulp_port_db_svif_get(params->ulp_ctx, ifindex, svif_type, &svif);
+
+	if (ulp_port_db_svif_get(params->ulp_ctx, ifindex, svif_type, &svif)) {
+		BNXT_DRV_DBG(ERR, "ParseErr:ifindex is not valid\n");
+		return BNXT_TF_RC_ERROR;
+	}
+
 	svif = rte_cpu_to_be_16(svif);
 	mask = rte_cpu_to_be_16(mask);
 	hdr_field = &params->hdr_field[BNXT_ULP_PROTO_HDR_FIELD_SVIF_IDX];
diff --git a/drivers/net/bnxt/tf_ulp/ulp_sc_mgr.c b/drivers/net/bnxt/tf_ulp/ulp_sc_mgr.c
index 5fa8e240db..d17ea11526 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_sc_mgr.c
+++ b/drivers/net/bnxt/tf_ulp/ulp_sc_mgr.c
@@ -191,6 +191,8 @@  static uint32_t ulp_stats_cache_main_loop(void *arg)
 	uint8_t *data;
 	int rc;
 
+	memset(&batch_info, 0, sizeof(batch_info));
+
 	while (true) {
 		ctxt = NULL;
 		while (!ctxt) {