DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] memzone: remove unnecessary null checks
@ 2024-06-18 23:25 Stephen Hemminger
  2024-06-19  0:15 ` Tyler Retzlaff
  2024-06-19  7:14 ` Morten Brørup
  0 siblings, 2 replies; 4+ messages in thread
From: Stephen Hemminger @ 2024-06-18 23:25 UTC (permalink / raw)
  To: dev
  Cc: Stephen Hemminger, Srikanth Yalavarthi, Kai Ji, Pablo de Lara,
	Chengwen Feng, Jeroen de Borst, Rushil Gupta, Joshua Washington,
	Devendra Singh Rawat, Alok Prasad, Jochen Behrens, Reshma Pattan

The function rte_memzone_free() already checks if the argument
is NULL. Add it to the coccinelle fix script and correct
all the existing code.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test-mldev/test_inference_common.c | 6 ++----
 devtools/cocci/nullfree.cocci          | 3 +++
 drivers/crypto/ipsec_mb/ipsec_mb_ops.c | 3 +--
 drivers/dma/hisilicon/hisi_dmadev.c    | 3 +--
 drivers/net/gve/gve_ethdev.c           | 3 +--
 drivers/net/qede/qede_filter.c         | 3 +--
 drivers/net/vmxnet3/vmxnet3_ethdev.c   | 3 +--
 lib/latencystats/rte_latencystats.c    | 3 +--
 8 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/app/test-mldev/test_inference_common.c b/app/test-mldev/test_inference_common.c
index 36629210ee..3b77f37010 100644
--- a/app/test-mldev/test_inference_common.c
+++ b/app/test-mldev/test_inference_common.c
@@ -870,8 +870,7 @@ ml_inference_iomem_setup(struct ml_test *test, struct ml_options *opt, uint16_t
 	return 0;
 
 error:
-	if (mz != NULL)
-		rte_memzone_free(mz);
+	rte_memzone_free(mz);
 
 	if (t->model[fid].io_pool != NULL) {
 		rte_mempool_free(t->model[fid].io_pool);
@@ -895,8 +894,7 @@ ml_inference_iomem_destroy(struct ml_test *test, struct ml_options *opt, uint16_
 	/* release user data memzone */
 	sprintf(mz_name, "ml_user_data_%d", fid);
 	mz = rte_memzone_lookup(mz_name);
-	if (mz != NULL)
-		rte_memzone_free(mz);
+	rte_memzone_free(mz);
 
 	/* destroy io pool */
 	sprintf(mp_name, "ml_io_pool_%d", fid);
diff --git a/devtools/cocci/nullfree.cocci b/devtools/cocci/nullfree.cocci
index c58aad4fb7..c0526a2a3f 100644
--- a/devtools/cocci/nullfree.cocci
+++ b/devtools/cocci/nullfree.cocci
@@ -73,6 +73,9 @@ expression E;
 - if (E != NULL) rte_mempool_free(E);
 + rte_mempool_free(E);
 |
+- if (E != NULL) rte_memzone_free(E);
++ rte_memzone_free(E);
+|
 - if (E != NULL) rte_pktmbuf_free(E);
 + rte_pktmbuf_free(E);
 |
diff --git a/drivers/crypto/ipsec_mb/ipsec_mb_ops.c b/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
index f21f9cc5a0..ba899604d2 100644
--- a/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
+++ b/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
@@ -336,8 +336,7 @@ ipsec_mb_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
 #else
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
 		return ret;
-	if (qp->mb_mgr_mz)
-		rte_memzone_free(qp->mb_mgr_mz);
+	rte_memzone_free(qp->mb_mgr_mz);
 #endif
 	rte_free(qp);
 	return ret;
diff --git a/drivers/dma/hisilicon/hisi_dmadev.c b/drivers/dma/hisilicon/hisi_dmadev.c
index 22303e7bef..e96bc1d654 100644
--- a/drivers/dma/hisilicon/hisi_dmadev.c
+++ b/drivers/dma/hisilicon/hisi_dmadev.c
@@ -310,8 +310,7 @@ hisi_dma_alloc_iomem(struct hisi_dma_dev *hw, uint16_t ring_size,
 static void
 hisi_dma_free_iomem(struct hisi_dma_dev *hw)
 {
-	if (hw->iomz != NULL)
-		rte_memzone_free(hw->iomz);
+	rte_memzone_free(hw->iomz);
 
 	hw->iomz = NULL;
 	hw->sqe = NULL;
diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
index 475745b9c0..0b29317497 100644
--- a/drivers/net/gve/gve_ethdev.c
+++ b/drivers/net/gve/gve_ethdev.c
@@ -77,8 +77,7 @@ gve_free_qpls(struct gve_priv *priv)
 		return;
 
 	for (i = 0; i < nb_txqs + nb_rxqs; i++) {
-		if (priv->qpl[i].mz != NULL)
-			rte_memzone_free(priv->qpl[i].mz);
+		rte_memzone_free(priv->qpl[i].mz);
 		rte_free(priv->qpl[i].page_buses);
 	}
 
diff --git a/drivers/net/qede/qede_filter.c b/drivers/net/qede/qede_filter.c
index e547b24a73..d98266eac5 100644
--- a/drivers/net/qede/qede_filter.c
+++ b/drivers/net/qede/qede_filter.c
@@ -158,8 +158,7 @@ void qede_fdir_dealloc_resc(struct rte_eth_dev *eth_dev)
 
 	SLIST_FOREACH(tmp, &qdev->arfs_info.arfs_list_head, list) {
 		if (tmp) {
-			if (tmp->mz)
-				rte_memzone_free(tmp->mz);
+			rte_memzone_free(tmp->mz);
 			SLIST_REMOVE(&qdev->arfs_info.arfs_list_head, tmp,
 				     qede_arfs_entry, list);
 			rte_free(tmp);
diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c b/drivers/net/vmxnet3/vmxnet3_ethdev.c
index ce7c347254..467fb61137 100644
--- a/drivers/net/vmxnet3/vmxnet3_ethdev.c
+++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c
@@ -189,8 +189,7 @@ gpa_zone_reserve(struct rte_eth_dev *dev, uint32_t size,
 
 	mz = rte_memzone_lookup(z_name);
 	if (!reuse) {
-		if (mz)
-			rte_memzone_free(mz);
+		rte_memzone_free(mz);
 		return rte_memzone_reserve_aligned(z_name, size, socket_id,
 				RTE_MEMZONE_IOVA_CONTIG, align);
 	}
diff --git a/lib/latencystats/rte_latencystats.c b/lib/latencystats/rte_latencystats.c
index cae4b50878..3bec205427 100644
--- a/lib/latencystats/rte_latencystats.c
+++ b/lib/latencystats/rte_latencystats.c
@@ -336,8 +336,7 @@ rte_latencystats_uninit(void)
 
 	/* free up the memzone */
 	mz = rte_memzone_lookup(MZ_RTE_LATENCY_STATS);
-	if (mz)
-		rte_memzone_free(mz);
+	rte_memzone_free(mz);
 
 	return 0;
 }
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-07 14:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-18 23:25 [PATCH] memzone: remove unnecessary null checks Stephen Hemminger
2024-06-19  0:15 ` Tyler Retzlaff
2024-07-07 12:52   ` Thomas Monjalon
2024-06-19  7:14 ` Morten Brørup

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).