Skip to contentSkip to conversation

remove unnecessary null check before free/rte_free

PATCH In review Stephen Hemminger 2 participants 2 messages Oct 24, 2023 – Nov 6, 2023 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 remove unnecessary null check before free/rte_free

This is the latest round of places that are checking for NULL pointer before calling free or rte_free. It is result of applying the nullfree.cocci script.

---
 app/test/test_cryptodev_asym.c   | 3 +--
 app/test/test_reassembly_perf.c  | 3 +--
 drivers/net/bnxt/bnxt_ethdev.c   | 3 +--
 drivers/net/bnxt/bnxt_vnic.c     | 3 +--
 drivers/net/cpfl/cpfl_fxp_rule.c | 3 +--
 drivers/net/nfp/nfp_ipsec.c      | 3 +--
 drivers/net/qede/base/bcm_osal.c | 3 +--
 7 files changed, 7 insertions(+), 14 deletions(-)
app/test/test_cryptodev_asym.c +1 -2
index 94bb091df352..cc06a4de027c 100644
@@ -565,8 +565,7 @@ ut_teardown_asym(void)
 
 	if (self->sess != NULL)
 		rte_cryptodev_asym_session_free(dev_id, self->sess);
-	if (self->op != NULL)
-		rte_crypto_op_free(self->op);
+	rte_crypto_op_free(self->op);
 	self->sess = NULL;
 	self->op = NULL;
 	self->result_op = NULL;
app/test/test_reassembly_perf.c +1 -2
index 4b4929d77798..3912179022fc 100644
@@ -81,8 +81,7 @@ reassembly_test_teardown(void)
 	if (frag_tbl != NULL)
 		rte_ip_frag_table_destroy(frag_tbl);
 
-	if (pkt_pool != NULL)
-		rte_mempool_free(pkt_pool);
+	rte_mempool_free(pkt_pool);
 }
 
 static void
drivers/net/bnxt/bnxt_ethdev.c +1 -2
index 5c4d96d4b14a..acf7e6e46e23 100644
@@ -6004,8 +6004,7 @@ static void bnxt_free_ctx_mem_buf(struct bnxt_ctx_mem_buf_info *ctx)
 	if (!ctx)
 		return;
 
-	if (ctx->va)
-		rte_free(ctx->va);
+	rte_free(ctx->va);
 
 	ctx->va = NULL;
 	ctx->dma = RTE_BAD_IOVA;
drivers/net/bnxt/bnxt_vnic.c +1 -2
index 2be456956ddc..f86d27fd7965 100644
@@ -847,8 +847,7 @@ bnxt_vnic_rss_hash_algo_update(struct bnxt *bp,
 
 int32_t bnxt_vnic_queue_db_deinit(struct bnxt *bp)
 {
-	if (bp->vnic_queue_db.rss_q_db != NULL)
-		rte_hash_free(bp->vnic_queue_db.rss_q_db);
+	rte_hash_free(bp->vnic_queue_db.rss_q_db);
 	return 0;
 }
 
drivers/net/cpfl/cpfl_fxp_rule.c +1 -2
index ea65e205072a..b6e4ac29e2c7 100644
@@ -55,8 +55,7 @@ cpfl_send_ctlq_msg(struct idpf_hw *hw, struct idpf_ctlq_info *cq, u16 num_q_msg,
 	}
 
 send_err:
-	if (msg_ptr_list)
-		free(msg_ptr_list);
+	free(msg_ptr_list);
 err:
 	return ret;
 }
drivers/net/nfp/nfp_ipsec.c +1 -2
index a76ba2a91d00..c1e1862d7ce8 100644
@@ -1415,8 +1415,7 @@ nfp_ipsec_init(struct rte_eth_dev *dev)
 static void
 nfp_ipsec_ctx_destroy(struct rte_eth_dev *dev)
 {
-	if (dev->security_ctx != NULL)
-		rte_free(dev->security_ctx);
+	rte_free(dev->security_ctx);
 }
 
 void
drivers/net/qede/base/bcm_osal.c +1 -2
index 638d0065ef14..2edeb38d6449 100644
@@ -69,8 +69,7 @@ int ecore_mz_mapping_alloc(void)
 void ecore_mz_mapping_free(void)
 {
 	if (__atomic_fetch_sub(&ref_cnt, 1, __ATOMIC_RELAXED) - 1 == 0) {
-		if (ecore_mz_mapping)
-			rte_free(ecore_mz_mapping);
+		rte_free(ecore_mz_mapping);
 		ecore_mz_mapping = NULL;
 	}
 }
Signature · 1 line
2.39.2
#1 lore raw

25/10/2023 00:58, Stephen Hemminger:

Quoted 5 lines

This is the latest round of places that are checking for NULL pointer before calling free or rte_free. It is result of applying the nullfree.cocci script.

Applied and re-run with more fixes in new ml/cnxk code, thanks.