DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 0/4] Remove unnecessary null free checks
@ 2023-03-23  1:04 Stephen Hemminger
  2023-03-23  1:04 ` [PATCH 1/4] mldev: remove " Stephen Hemminger
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Stephen Hemminger @ 2023-03-23  1:04 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger

These were produced by using coccinelle script.
  $ ./devtools/cocci.sh ./devtools/cocci/nullfree.cocci

Stephen Hemminger (4):
  mldev: remove unnecessary null free checks
  ml/cnkx: remove unnecessary null checks
  graph: remove unnicessary null checks
  examples/fips_validation: remove unneeded null checks

 app/test-mldev/test_device_ops.c       |  6 ++----
 app/test-mldev/test_inference_common.c | 24 ++++++++----------------
 app/test-mldev/test_model_ops.c        |  6 ++----
 drivers/ml/cnxk/cn10k_ml_dev.c         |  9 +++------
 drivers/ml/cnxk/cn10k_ml_ops.c         | 12 ++++--------
 examples/fips_validation/main.c        |  6 ++----
 lib/graph/graph_pcap.c                 |  3 +--
 lib/mldev/rte_mldev.c                  |  3 +--
 8 files changed, 23 insertions(+), 46 deletions(-)

-- 
2.39.2


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

* [PATCH 1/4] mldev: remove unnecessary null free checks
  2023-03-23  1:04 [PATCH 0/4] Remove unnecessary null free checks Stephen Hemminger
@ 2023-03-23  1:04 ` Stephen Hemminger
  2023-03-23  4:06   ` [EXT] " Srikanth Yalavarthi
  2023-03-23  1:04 ` [PATCH 2/4] ml/cnkx: remove unnecessary null checks Stephen Hemminger
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2023-03-23  1:04 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Srikanth Yalavarthi

These are places where mldev is doing unnecessary checks
for calling free() style functions.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test-mldev/test_device_ops.c       |  6 ++----
 app/test-mldev/test_inference_common.c | 24 ++++++++----------------
 app/test-mldev/test_model_ops.c        |  6 ++----
 lib/mldev/rte_mldev.c                  |  3 +--
 4 files changed, 13 insertions(+), 26 deletions(-)

diff --git a/app/test-mldev/test_device_ops.c b/app/test-mldev/test_device_ops.c
index be0c5f0780d9..81b3ca18f36b 100644
--- a/app/test-mldev/test_device_ops.c
+++ b/app/test-mldev/test_device_ops.c
@@ -70,8 +70,7 @@ test_device_setup(struct ml_test *test, struct ml_options *opt)
 	return 0;
 
 error:
-	if (test_device != NULL)
-		rte_free(test_device);
+	rte_free(test_device);
 
 	return ret;
 }
@@ -84,8 +83,7 @@ test_device_destroy(struct ml_test *test, struct ml_options *opt)
 	RTE_SET_USED(opt);
 
 	t = ml_test_priv(test);
-	if (t != NULL)
-		rte_free(t);
+	rte_free(t);
 }
 
 static int
diff --git a/app/test-mldev/test_inference_common.c b/app/test-mldev/test_inference_common.c
index eba37c50e96c..af831fc1bf4c 100644
--- a/app/test-mldev/test_inference_common.c
+++ b/app/test-mldev/test_inference_common.c
@@ -492,8 +492,7 @@ test_inference_setup(struct ml_test *test, struct ml_options *opt)
 	return 0;
 
 error:
-	if (test_inference != NULL)
-		rte_free(test_inference);
+	rte_free(test_inference);
 
 	return ret;
 }
@@ -506,8 +505,7 @@ test_inference_destroy(struct ml_test *test, struct ml_options *opt)
 	RTE_SET_USED(opt);
 
 	t = ml_test_priv(test);
-	if (t != NULL)
-		rte_free(t);
+	rte_free(t);
 }
 
 int
@@ -748,8 +746,7 @@ ml_inference_iomem_destroy(struct ml_test *test, struct ml_options *opt, uint16_
 	/* destroy io pool */
 	sprintf(mp_name, "ml_io_pool_%d", fid);
 	mp = rte_mempool_lookup(mp_name);
-	if (mp != NULL)
-		rte_mempool_free(mp);
+	rte_mempool_free(mp);
 }
 
 int
@@ -776,8 +773,7 @@ ml_inference_mem_destroy(struct ml_test *test, struct ml_options *opt)
 	RTE_SET_USED(opt);
 
 	/* release op pool */
-	if (t->op_pool != NULL)
-		rte_mempool_free(t->op_pool);
+	rte_mempool_free(t->op_pool);
 }
 
 static bool
@@ -1088,11 +1084,9 @@ ml_inference_stats_get(struct ml_test *test, struct ml_options *opt)
 	print_line(80);
 
 	/* release buffers */
-	if (t->xstats_map)
-		rte_free(t->xstats_map);
+	rte_free(t->xstats_map);
 
-	if (t->xstats_values)
-		rte_free(t->xstats_values);
+	rte_free(t->xstats_values);
 
 	/* print end-to-end stats */
 	freq = rte_get_tsc_hz();
@@ -1129,11 +1123,9 @@ ml_inference_stats_get(struct ml_test *test, struct ml_options *opt)
 	return 0;
 
 error:
-	if (t->xstats_map)
-		rte_free(t->xstats_map);
+	rte_free(t->xstats_map);
 
-	if (t->xstats_values)
-		rte_free(t->xstats_values);
+	rte_free(t->xstats_values);
 
 	return ret;
 }
diff --git a/app/test-mldev/test_model_ops.c b/app/test-mldev/test_model_ops.c
index 0202b31190f8..5bbbcb1a6c0b 100644
--- a/app/test-mldev/test_model_ops.c
+++ b/app/test-mldev/test_model_ops.c
@@ -93,8 +93,7 @@ test_model_ops_setup(struct ml_test *test, struct ml_options *opt)
 	return 0;
 
 error:
-	if (test_model_ops != NULL)
-		rte_free(test_model_ops);
+	rte_free(test_model_ops);
 
 	return ret;
 }
@@ -107,8 +106,7 @@ test_model_ops_destroy(struct ml_test *test, struct ml_options *opt)
 	RTE_SET_USED(opt);
 
 	t = ml_test_priv(test);
-	if (t != NULL)
-		rte_free(t);
+	rte_free(t);
 }
 
 static int
diff --git a/lib/mldev/rte_mldev.c b/lib/mldev/rte_mldev.c
index 50ebeb1bfe8d..f5904a0d4a90 100644
--- a/lib/mldev/rte_mldev.c
+++ b/lib/mldev/rte_mldev.c
@@ -836,8 +836,7 @@ rte_ml_op_pool_create(const char *name, unsigned int nb_elts, unsigned int cache
 void
 rte_ml_op_pool_free(struct rte_mempool *mempool)
 {
-	if (mempool != NULL)
-		rte_mempool_free(mempool);
+	rte_mempool_free(mempool);
 }
 
 uint16_t
-- 
2.39.2


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

* [PATCH 2/4] ml/cnkx: remove unnecessary null checks
  2023-03-23  1:04 [PATCH 0/4] Remove unnecessary null free checks Stephen Hemminger
  2023-03-23  1:04 ` [PATCH 1/4] mldev: remove " Stephen Hemminger
@ 2023-03-23  1:04 ` Stephen Hemminger
  2023-03-23  4:14   ` [EXT] " Srikanth Yalavarthi
  2023-03-23  1:04 ` [PATCH 3/4] graph: remove unnicessary " Stephen Hemminger
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2023-03-23  1:04 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Srikanth Yalavarthi

These are places where null check is not necessary before
calling free.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/ml/cnxk/cn10k_ml_dev.c |  9 +++------
 drivers/ml/cnxk/cn10k_ml_ops.c | 12 ++++--------
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/ml/cnxk/cn10k_ml_dev.c b/drivers/ml/cnxk/cn10k_ml_dev.c
index bba3c9022e6b..983138a7f237 100644
--- a/drivers/ml/cnxk/cn10k_ml_dev.c
+++ b/drivers/ml/cnxk/cn10k_ml_dev.c
@@ -319,8 +319,7 @@ cn10k_mldev_parse_devargs(struct rte_devargs *devargs, struct cn10k_ml_dev *mlde
 	plt_info("ML: %s = %d", CN10K_ML_OCM_PAGE_SIZE, mldev->ocm_page_size);
 
 exit:
-	if (kvlist)
-		rte_kvargs_free(kvlist);
+	rte_kvargs_free(kvlist);
 
 	return ret;
 }
@@ -795,8 +794,7 @@ cn10k_ml_fw_load(struct cn10k_ml_dev *mldev)
 	mz = plt_memzone_reserve_aligned(FW_MEMZONE_NAME, mz_size, 0, ML_CN10K_ALIGN_SIZE);
 	if (mz == NULL) {
 		plt_err("plt_memzone_reserve failed : %s", FW_MEMZONE_NAME);
-		if (fw_buffer != NULL)
-			free(fw_buffer);
+		free(fw_buffer);
 		return -ENOMEM;
 	}
 	fw->req = mz->addr;
@@ -813,8 +811,7 @@ cn10k_ml_fw_load(struct cn10k_ml_dev *mldev)
 	if (roc_env_is_emulator() || roc_env_is_hw()) {
 		fw->data = PLT_PTR_ADD(mz->addr, sizeof(struct cn10k_ml_req));
 		ret = cn10k_ml_fw_load_cn10ka(fw, fw_buffer, fw_size);
-		if (fw_buffer != NULL)
-			free(fw_buffer);
+		free(fw_buffer);
 	} else if (roc_env_is_asim()) {
 		fw->data = NULL;
 		ret = cn10k_ml_fw_load_asim(fw);
diff --git a/drivers/ml/cnxk/cn10k_ml_ops.c b/drivers/ml/cnxk/cn10k_ml_ops.c
index 4df2ca0e8c26..b5eaa24e831c 100644
--- a/drivers/ml/cnxk/cn10k_ml_ops.c
+++ b/drivers/ml/cnxk/cn10k_ml_ops.c
@@ -845,11 +845,9 @@ cn10k_ml_dev_configure(struct rte_ml_dev *dev, const struct rte_ml_dev_config *c
 	return 0;
 
 error:
-	if (dev->data->queue_pairs != NULL)
-		rte_free(dev->data->queue_pairs);
+	rte_free(dev->data->queue_pairs);
 
-	if (dev->data->models != NULL)
-		rte_free(dev->data->models);
+	rte_free(dev->data->models);
 
 	return ret;
 }
@@ -887,8 +885,7 @@ cn10k_ml_dev_close(struct rte_ml_dev *dev)
 		}
 	}
 
-	if (dev->data->models)
-		rte_free(dev->data->models);
+	rte_free(dev->data->models);
 
 	/* Destroy all queue pairs */
 	for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
@@ -900,8 +897,7 @@ cn10k_ml_dev_close(struct rte_ml_dev *dev)
 		}
 	}
 
-	if (dev->data->queue_pairs)
-		rte_free(dev->data->queue_pairs);
+	rte_free(dev->data->queue_pairs);
 
 	/* Unload firmware */
 	cn10k_ml_fw_unload(mldev);
-- 
2.39.2


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

* [PATCH 3/4] graph: remove unnicessary null checks
  2023-03-23  1:04 [PATCH 0/4] Remove unnecessary null free checks Stephen Hemminger
  2023-03-23  1:04 ` [PATCH 1/4] mldev: remove " Stephen Hemminger
  2023-03-23  1:04 ` [PATCH 2/4] ml/cnkx: remove unnecessary null checks Stephen Hemminger
@ 2023-03-23  1:04 ` Stephen Hemminger
  2023-03-23  1:04 ` [PATCH 4/4] examples/fips_validation: remove unneeded " Stephen Hemminger
  2023-03-23  9:33 ` [PATCH 0/4] Remove unnecessary null free checks Thomas Monjalon
  4 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2023-03-23  1:04 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Jerin Jacob, Kiran Kumar K, Nithin Dabilpuram

Checking for null before calling rte_mempool_free is
unnecessary.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/graph/graph_pcap.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/graph/graph_pcap.c b/lib/graph/graph_pcap.c
index 9cbd1b8fdb6c..6c433300290b 100644
--- a/lib/graph/graph_pcap.c
+++ b/lib/graph/graph_pcap.c
@@ -40,8 +40,7 @@ void
 graph_pcap_exit(struct rte_graph *graph)
 {
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
-		if (pkt_mp)
-			rte_mempool_free(pkt_mp);
+		rte_mempool_free(pkt_mp);
 
 	if (pcapng_fd) {
 		rte_pcapng_close(pcapng_fd);
-- 
2.39.2


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

* [PATCH 4/4] examples/fips_validation: remove unneeded null checks
  2023-03-23  1:04 [PATCH 0/4] Remove unnecessary null free checks Stephen Hemminger
                   ` (2 preceding siblings ...)
  2023-03-23  1:04 ` [PATCH 3/4] graph: remove unnicessary " Stephen Hemminger
@ 2023-03-23  1:04 ` Stephen Hemminger
  2023-03-23  9:33 ` [PATCH 0/4] Remove unnecessary null free checks Thomas Monjalon
  4 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2023-03-23  1:04 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Brian Dooley

No check for null pointer is necessary before calling free().

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 examples/fips_validation/main.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c
index 2c4353185edd..4c231fdb29cd 100644
--- a/examples/fips_validation/main.c
+++ b/examples/fips_validation/main.c
@@ -2288,8 +2288,7 @@ fips_mct_sha_test(void)
 
 	max_outlen = md_blocks * vec.cipher_auth.digest.len;
 
-	if (vec.cipher_auth.digest.val)
-		free(vec.cipher_auth.digest.val);
+	free(vec.cipher_auth.digest.val);
 
 	vec.cipher_auth.digest.val = calloc(1, max_outlen);
 
@@ -2382,8 +2381,7 @@ fips_mct_shake_test(void)
 
 	max_outlen = vec.cipher_auth.digest.len;
 
-	if (vec.cipher_auth.digest.val)
-		free(vec.cipher_auth.digest.val);
+	free(vec.cipher_auth.digest.val);
 
 	vec.cipher_auth.digest.val = calloc(1, max_outlen);
 
-- 
2.39.2


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

* RE: [EXT] [PATCH 1/4] mldev: remove unnecessary null free checks
  2023-03-23  1:04 ` [PATCH 1/4] mldev: remove " Stephen Hemminger
@ 2023-03-23  4:06   ` Srikanth Yalavarthi
  0 siblings, 0 replies; 8+ messages in thread
From: Srikanth Yalavarthi @ 2023-03-23  4:06 UTC (permalink / raw)
  To: Stephen Hemminger, dev; +Cc: Srikanth Yalavarthi

> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: 23 March 2023 06:34
> To: dev@dpdk.org
> Cc: Stephen Hemminger <stephen@networkplumber.org>; Srikanth
> Yalavarthi <syalavarthi@marvell.com>; Srikanth Yalavarthi
> <syalavarthi@marvell.com>
> Subject: [EXT] [PATCH 1/4] mldev: remove unnecessary null free checks
> 
> External Email
> 
> ----------------------------------------------------------------------
> These are places where mldev is doing unnecessary checks for calling free()
> style functions.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Srikanth Yalavarthi <syalavarthi@marvell.com>


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

* RE: [EXT] [PATCH 2/4] ml/cnkx: remove unnecessary null checks
  2023-03-23  1:04 ` [PATCH 2/4] ml/cnkx: remove unnecessary null checks Stephen Hemminger
@ 2023-03-23  4:14   ` Srikanth Yalavarthi
  0 siblings, 0 replies; 8+ messages in thread
From: Srikanth Yalavarthi @ 2023-03-23  4:14 UTC (permalink / raw)
  To: Stephen Hemminger, dev; +Cc: Srikanth Yalavarthi

> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: 23 March 2023 06:34
> To: dev@dpdk.org
> Cc: Stephen Hemminger <stephen@networkplumber.org>; Srikanth
> Yalavarthi <syalavarthi@marvell.com>; Srikanth Yalavarthi
> <syalavarthi@marvell.com>
> Subject: [EXT] [PATCH 2/4] ml/cnkx: remove unnecessary null checks
> 
> External Email
> 
> ----------------------------------------------------------------------
> These are places where null check is not necessary before calling free.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Srikanth Yalavarthi <syalavarthi@marvell.com>

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

* Re: [PATCH 0/4] Remove unnecessary null free checks
  2023-03-23  1:04 [PATCH 0/4] Remove unnecessary null free checks Stephen Hemminger
                   ` (3 preceding siblings ...)
  2023-03-23  1:04 ` [PATCH 4/4] examples/fips_validation: remove unneeded " Stephen Hemminger
@ 2023-03-23  9:33 ` Thomas Monjalon
  4 siblings, 0 replies; 8+ messages in thread
From: Thomas Monjalon @ 2023-03-23  9:33 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev

23/03/2023 02:04, Stephen Hemminger:
> These were produced by using coccinelle script.
>   $ ./devtools/cocci.sh ./devtools/cocci/nullfree.cocci
> 
> Stephen Hemminger (4):
>   mldev: remove unnecessary null free checks
>   ml/cnkx: remove unnecessary null checks
>   graph: remove unnicessary null checks
>   examples/fips_validation: remove unneeded null checks

Fixed typos in titles and applied, thanks.



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

end of thread, other threads:[~2023-03-23  9:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-23  1:04 [PATCH 0/4] Remove unnecessary null free checks Stephen Hemminger
2023-03-23  1:04 ` [PATCH 1/4] mldev: remove " Stephen Hemminger
2023-03-23  4:06   ` [EXT] " Srikanth Yalavarthi
2023-03-23  1:04 ` [PATCH 2/4] ml/cnkx: remove unnecessary null checks Stephen Hemminger
2023-03-23  4:14   ` [EXT] " Srikanth Yalavarthi
2023-03-23  1:04 ` [PATCH 3/4] graph: remove unnicessary " Stephen Hemminger
2023-03-23  1:04 ` [PATCH 4/4] examples/fips_validation: remove unneeded " Stephen Hemminger
2023-03-23  9:33 ` [PATCH 0/4] Remove unnecessary null free checks Thomas Monjalon

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).