DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Olivier Matz <olivier.matz@6wind.com>,
	Akhil Goyal <gakhil@marvell.com>,
	Fan Zhang <roy.fan.zhang@intel.com>,
	Yipeng Wang <yipeng1.wang@intel.com>,
	Sameh Gobriel <sameh.gobriel@intel.com>,
	Bruce Richardson <bruce.richardson@intel.com>,
	Vladimir Medvedkin <vladimir.medvedkin@intel.com>,
	Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>,
	Konstantin Ananyev <konstantin.ananyev@intel.com>,
	Anatoly Burakov <anatoly.burakov@intel.com>,
	Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Subject: [PATCH v3 5/8] test: remove unnecessary NULL checks before free
Date: Sun, 20 Feb 2022 10:21:44 -0800	[thread overview]
Message-ID: <20220220182147.9750-6-stephen@networkplumber.org> (raw)
In-Reply-To: <20220220182147.9750-1-stephen@networkplumber.org>

These are all cases in test code where there is unnecessary
NULL check before free caught by coccinelle nullfree script.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test/test_cmdline_lib.c           |  3 +--
 app/test/test_cryptodev.c             |  9 +++-----
 app/test/test_cryptodev_asym.c        | 30 +++++++++------------------
 app/test/test_cryptodev_blockcipher.c |  3 +--
 app/test/test_func_reentrancy.c       |  3 +--
 app/test/test_hash.c                  |  3 +--
 6 files changed, 17 insertions(+), 34 deletions(-)

diff --git a/app/test/test_cmdline_lib.c b/app/test/test_cmdline_lib.c
index fcd58cb76af1..87c105936650 100644
--- a/app/test/test_cmdline_lib.c
+++ b/app/test/test_cmdline_lib.c
@@ -229,8 +229,7 @@ test_cmdline_fns(void)
 
 error:
 	printf("Error: function accepted null parameter!\n");
-	if (cl != NULL)
-		cmdline_free(cl);
+	cmdline_free(cl);
 	return -1;
 }
 
diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index a63c199964d4..1d9f615255c4 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -1451,8 +1451,7 @@ ut_teardown(void)
 	}
 
 	/* free crypto operation structure */
-	if (ut_params->op)
-		rte_crypto_op_free(ut_params->op);
+	rte_crypto_op_free(ut_params->op);
 
 	/*
 	 * free mbuf - both obuf and ibuf are usually the same,
@@ -11653,8 +11652,7 @@ test_multi_session(void)
 			aes_cbc_iv),
 			"Failed to perform decrypt on request number %u.", i);
 		/* free crypto operation structure */
-		if (ut_params->op)
-			rte_crypto_op_free(ut_params->op);
+		rte_crypto_op_free(ut_params->op);
 
 		/*
 		 * free mbuf - both obuf and ibuf are usually the same,
@@ -11797,8 +11795,7 @@ test_multi_session_random_usage(void)
 					ut_paramz[j].iv),
 			"Failed to perform decrypt on request number %u.", i);
 
-		if (ut_paramz[j].ut_params.op)
-			rte_crypto_op_free(ut_paramz[j].ut_params.op);
+		rte_crypto_op_free(ut_paramz[j].ut_params.op);
 
 		/*
 		 * free mbuf - both obuf and ibuf are usually the same,
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 7cda8bb081f0..9b4d9db59297 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -507,8 +507,7 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 		if (sess != NULL)
 			rte_cryptodev_asym_session_free(dev_id, sess);
 
-		if (op != NULL)
-			rte_crypto_op_free(op);
+		rte_crypto_op_free(op);
 
 		rte_free(result);
 
@@ -1114,8 +1113,7 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 error_exit:
 	if (sess != NULL)
 		rte_cryptodev_asym_session_free(dev_id, sess);
-	if (op != NULL)
-		rte_crypto_op_free(op);
+	rte_crypto_op_free(op);
 	return status;
 }
 
@@ -1193,8 +1191,7 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 error_exit:
 	if (sess != NULL)
 		rte_cryptodev_asym_session_free(dev_id, sess);
-	if (op != NULL)
-		rte_crypto_op_free(op);
+	rte_crypto_op_free(op);
 
 	return status;
 }
@@ -1283,8 +1280,7 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 error_exit:
 	if (sess != NULL)
 		rte_cryptodev_asym_session_free(dev_id, sess);
-	if (op != NULL)
-		rte_crypto_op_free(op);
+	rte_crypto_op_free(op);
 
 	return status;
 }
@@ -1370,8 +1366,7 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 error_exit:
 	if (sess != NULL)
 		rte_cryptodev_asym_session_free(dev_id, sess);
-	if (op != NULL)
-		rte_crypto_op_free(op);
+	rte_crypto_op_free(op);
 
 	return status;
 }
@@ -1481,8 +1476,7 @@ test_mod_inv(void)
 	if (sess)
 		rte_cryptodev_asym_session_free(dev_id, sess);
 
-	if (op)
-		rte_crypto_op_free(op);
+	rte_crypto_op_free(op);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -1593,8 +1587,7 @@ test_mod_exp(void)
 	if (sess != NULL)
 		rte_cryptodev_asym_session_free(dev_id, sess);
 
-	if (op != NULL)
-		rte_crypto_op_free(op);
+	rte_crypto_op_free(op);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -1758,8 +1751,7 @@ test_dsa_sign(void)
 error_exit:
 	if (sess != NULL)
 		rte_cryptodev_asym_session_free(dev_id, sess);
-	if (op != NULL)
-		rte_crypto_op_free(op);
+	rte_crypto_op_free(op);
 	return status;
 }
 
@@ -1947,8 +1939,7 @@ test_ecdsa_sign_verify(enum curve curve_id)
 exit:
 	if (sess != NULL)
 		rte_cryptodev_asym_session_free(dev_id, sess);
-	if (op != NULL)
-		rte_crypto_op_free(op);
+	rte_crypto_op_free(op);
 	return status;
 };
 
@@ -2109,8 +2100,7 @@ test_ecpm(enum curve curve_id)
 exit:
 	if (sess != NULL)
 		rte_cryptodev_asym_session_free(dev_id, sess);
-	if (op != NULL)
-		rte_crypto_op_free(op);
+	rte_crypto_op_free(op);
 	return status;
 }
 
diff --git a/app/test/test_cryptodev_blockcipher.c b/app/test/test_cryptodev_blockcipher.c
index 494459195c49..954587ea5b18 100644
--- a/app/test/test_cryptodev_blockcipher.c
+++ b/app/test/test_cryptodev_blockcipher.c
@@ -811,8 +811,7 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t,
 		rte_free(auth_xform);
 	}
 
-	if (op)
-		rte_crypto_op_free(op);
+	rte_crypto_op_free(op);
 
 	rte_pktmbuf_free(obuf);
 
diff --git a/app/test/test_func_reentrancy.c b/app/test/test_func_reentrancy.c
index 67e69ad53588..d1ed5d4abcfc 100644
--- a/app/test/test_func_reentrancy.c
+++ b/app/test/test_func_reentrancy.c
@@ -278,8 +278,7 @@ fbk_clean(unsigned lcore_id)
 	int i;
 
 	handle = rte_fbk_hash_find_existing("fr_test_once");
-	if (handle != NULL)
-		rte_fbk_hash_free(handle);
+	rte_fbk_hash_free(handle);
 
 	for (i = 0; i < MAX_ITER_MULTI; i++) {
 		snprintf(fbk_name, sizeof(fbk_name), "fr_test_%d_%d",  lcore_id, i);
diff --git a/app/test/test_hash.c b/app/test/test_hash.c
index d522cb7f8cbf..3e45afaa67fc 100644
--- a/app/test/test_hash.c
+++ b/app/test/test_hash.c
@@ -1159,8 +1159,7 @@ fbk_hash_unit_test(void)
 	RETURN_IF_ERROR_FBK(handle == NULL, "fbk hash creation should have succeeded");
 
 	tmp = rte_fbk_hash_create(&invalid_params_same_name_2);
-	if (tmp != NULL)
-		rte_fbk_hash_free(tmp);
+	rte_fbk_hash_free(tmp);
 	RETURN_IF_ERROR_FBK(tmp != NULL, "fbk hash creation should have failed");
 
 	/* we are not freeing  handle here because we need a hash list
-- 
2.34.1


  parent reply	other threads:[~2022-02-20 18:22 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-19 23:43 [PATCH 0/3] more unnecessary null checks Stephen Hemminger
2022-02-19 23:43 ` [PATCH 1/3] cocci/nullfree: add more functions Stephen Hemminger
2022-02-19 23:43 ` [PATCH 2/3] acl: remove unncessary null checks in calls to rte_acl_free() Stephen Hemminger
2022-02-19 23:43 ` [PATCH 3/3] lpm: remove unnecessary NULL checks Stephen Hemminger
2022-02-20  0:51 ` [PATCH v2 0/7] fix more unnecessary null checks Stephen Hemminger
2022-02-20  0:51   ` [PATCH v2 1/7] cocci/nullfree: add more functions Stephen Hemminger
2022-02-20  0:51   ` [PATCH v2 2/7] acl: remove unnecessary null checks Stephen Hemminger
2022-02-20  0:51   ` [PATCH v2 3/7] lpm: remove unnecessary NULL checks Stephen Hemminger
2022-02-20  0:51   ` [PATCH v2 4/7] lib: document existing free functions Stephen Hemminger
2022-02-20  0:51   ` [PATCH v2 5/7] test: remove unecessary NULL checks before free Stephen Hemminger
2022-02-20  0:51   ` [PATCH v2 6/7] fips_validation: remove unnecessary NULL check Stephen Hemminger
2022-02-20  0:51   ` [PATCH v2 7/7] event/sw: " Stephen Hemminger
2022-02-20  5:18 ` [PATCH 0/3] more unnecessary null checks Jerin Jacob
2022-02-20 18:21 ` [PATCH v3 0/8] yet more unnecessary NULL checks Stephen Hemminger
2022-02-20 18:21   ` [PATCH v3 1/8] cocci/nullfree: add more functions Stephen Hemminger
2022-02-20 18:21   ` [PATCH v3 2/8] acl: remove unnecessary null checks Stephen Hemminger
2022-02-20 18:21   ` [PATCH v3 3/8] lpm: remove unnecessary NULL checks Stephen Hemminger
2022-02-21  2:47     ` Ruifeng Wang
2022-02-21 15:51     ` Medvedkin, Vladimir
2022-02-20 18:21   ` [PATCH v3 4/8] lib: document existing free functions Stephen Hemminger
2022-02-27 20:48     ` Thomas Monjalon
2022-02-28  9:42       ` Bruce Richardson
2022-02-28 17:08         ` Stephen Hemminger
2022-06-22  9:23           ` Thomas Monjalon
2022-06-22 14:55             ` Stephen Hemminger
2022-02-20 18:21   ` Stephen Hemminger [this message]
2022-02-20 18:21   ` [PATCH v3 6/8] fips_validation: remove unnecessary NULL check Stephen Hemminger
2022-02-20 18:21   ` [PATCH v3 7/8] event/sw: " Stephen Hemminger
2022-02-20 18:21   ` [PATCH v3 8/8] pipeline: remove unnecessary checks for NULL pointer before free Stephen Hemminger
2022-06-22 20:52   ` [PATCH v4] lib: document existing free functions Stephen Hemminger
2022-06-23  0:37     ` fengchengwen
2022-06-24 12:35     ` David Marchand
2022-06-24 12:41   ` [PATCH v3 0/8] yet more unnecessary NULL checks David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220220182147.9750-6-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=anatoly.burakov@intel.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=gakhil@marvell.com \
    --cc=honnappa.nagarahalli@arm.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=olivier.matz@6wind.com \
    --cc=roy.fan.zhang@intel.com \
    --cc=sameh.gobriel@intel.com \
    --cc=vladimir.medvedkin@intel.com \
    --cc=yipeng1.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).