[v3,5/8] test: remove unnecessary NULL checks before free

Message ID 20220220182147.9750-6-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series yet more unnecessary NULL checks |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Feb. 20, 2022, 6:21 p.m. UTC
  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(-)
  

Patch

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