diff mbox series

[14/82] app/test: remove unnecessary NULL checks

Message ID 20220124000518.319850-15-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series remove unnecessary null checks | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Jan. 24, 2022, 12:04 a.m. UTC
Remove redundant NULL pointer checks before free functions
found by nullfree.cocci

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test/test_cksum.c                 |  3 +-
 app/test/test_compressdev.c           |  3 +-
 app/test/test_cryptodev.h             |  3 +-
 app/test/test_cryptodev_asym.c        |  3 +-
 app/test/test_cryptodev_blockcipher.c | 12 +++----
 app/test/test_func_reentrancy.c       | 15 +++------
 app/test/test_hash.c                  | 15 +++------
 app/test/test_hash_perf.c             |  7 +----
 app/test/test_link_bonding.c          |  9 ++----
 app/test/test_link_bonding_mode4.c    |  3 +-
 app/test/test_malloc.c                |  5 ++-
 app/test/test_mbuf.c                  | 45 +++++++++------------------
 app/test/test_pcapng.c                |  3 +-
 app/test/test_reorder.c               | 15 +++------
 app/test/virtual_pmd.c                |  3 +-
 15 files changed, 47 insertions(+), 97 deletions(-)
diff mbox series

Patch

diff --git a/app/test/test_cksum.c b/app/test/test_cksum.c
index cd983d7c01ce..6c15de9a9312 100644
--- a/app/test/test_cksum.c
+++ b/app/test/test_cksum.c
@@ -218,8 +218,7 @@  test_l4_cksum(struct rte_mempool *pktmbuf_pool, const char *pktdata, size_t len)
 	return 0;
 
 fail:
-	if (m)
-		rte_pktmbuf_free(m);
+	rte_pktmbuf_free(m);
 
 	return -1;
 }
diff --git a/app/test/test_compressdev.c b/app/test/test_compressdev.c
index 57c566aa9229..fbecaf9aaad4 100644
--- a/app/test/test_compressdev.c
+++ b/app/test/test_compressdev.c
@@ -2144,8 +2144,7 @@  test_deflate_comp_decomp(const struct interim_data_params *int_data,
 
 	if (stream != NULL)
 		rte_compressdev_stream_free(0, stream);
-	if (all_decomp_data != NULL)
-		rte_free(all_decomp_data);
+	rte_free(all_decomp_data);
 
 	/* Free compress private xforms */
 	for (i = 0; i < test_priv_data.num_priv_xforms; i++) {
diff --git a/app/test/test_cryptodev.h b/app/test/test_cryptodev.h
index 70f23a3f67d0..29a7d4db2b10 100644
--- a/app/test/test_cryptodev.h
+++ b/app/test/test_cryptodev.h
@@ -230,8 +230,7 @@  create_segmented_mbuf(struct rte_mempool *mbuf_pool, int pkt_len,
 	return mbuf;
 
 fail:
-	if (mbuf)
-		rte_pktmbuf_free(mbuf);
+	rte_pktmbuf_free(mbuf);
 	return NULL;
 }
 
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 68f4d8e7a6f9..8c68a12d74b2 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -518,8 +518,7 @@  test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 		if (op != NULL)
 			rte_crypto_op_free(op);
 
-		if (result != NULL)
-			rte_free(result);
+		rte_free(result);
 
 	return status;
 }
diff --git a/app/test/test_cryptodev_blockcipher.c b/app/test/test_cryptodev_blockcipher.c
index 5688a45377b2..127e2a53d379 100644
--- a/app/test/test_cryptodev_blockcipher.c
+++ b/app/test/test_cryptodev_blockcipher.c
@@ -805,20 +805,16 @@  test_blockcipher_one_case(const struct blockcipher_test_case *t,
 			rte_cryptodev_sym_session_clear(dev_id, sess);
 			rte_cryptodev_sym_session_free(sess);
 		}
-		if (cipher_xform)
-			rte_free(cipher_xform);
-		if (auth_xform)
-			rte_free(auth_xform);
+		rte_free(cipher_xform);
+		rte_free(auth_xform);
 	}
 
 	if (op)
 		rte_crypto_op_free(op);
 
-	if (obuf)
-		rte_pktmbuf_free(obuf);
+	rte_pktmbuf_free(obuf);
 
-	if (ibuf)
-		rte_pktmbuf_free(ibuf);
+	rte_pktmbuf_free(ibuf);
 
 	return status;
 }
diff --git a/app/test/test_func_reentrancy.c b/app/test/test_func_reentrancy.c
index ce40c3ce9631..64f27e20370f 100644
--- a/app/test/test_func_reentrancy.c
+++ b/app/test/test_func_reentrancy.c
@@ -89,15 +89,13 @@  ring_clean(unsigned int lcore_id)
 	int i;
 
 	rp = rte_ring_lookup("fr_test_once");
-	if (rp != NULL)
-		rte_ring_free(rp);
+	rte_ring_free(rp);
 
 	for (i = 0; i < MAX_ITER_MULTI; i++) {
 		snprintf(ring_name, sizeof(ring_name),
 				"fr_test_%d_%d", lcore_id, i);
 		rp = rte_ring_lookup(ring_name);
-		if (rp != NULL)
-			rte_ring_free(rp);
+		rte_ring_free(rp);
 	}
 }
 
@@ -152,15 +150,13 @@  mempool_clean(unsigned int lcore_id)
 	int i;
 
 	mp = rte_mempool_lookup("fr_test_once");
-	if (mp != NULL)
-		rte_mempool_free(mp);
+	rte_mempool_free(mp);
 
 	for (i = 0; i < MAX_ITER_MULTI; i++) {
 		snprintf(mempool_name, sizeof(mempool_name), "fr_test_%d_%d",
 			 lcore_id, i);
 		mp = rte_mempool_lookup(mempool_name);
-		if (mp != NULL)
-			rte_mempool_free(mp);
+		rte_mempool_free(mp);
 	}
 }
 
@@ -215,8 +211,7 @@  hash_clean(unsigned lcore_id)
 	int i;
 
 	handle = rte_hash_find_existing("fr_test_once");
-	if (handle != NULL)
-		rte_hash_free(handle);
+	rte_hash_free(handle);
 
 	for (i = 0; i < MAX_ITER_MULTI; i++) {
 		snprintf(hash_name, sizeof(hash_name), "fr_test_%d_%d",  lcore_id, i);
diff --git a/app/test/test_hash.c b/app/test/test_hash.c
index b99e8de1db71..d522cb7f8cbf 100644
--- a/app/test/test_hash.c
+++ b/app/test/test_hash.c
@@ -1654,8 +1654,7 @@  test_hash_add_delete_jhash2(void)
 	ret = 0;
 
 fail_jhash2:
-	if (handle != NULL)
-		rte_hash_free(handle);
+	rte_hash_free(handle);
 
 	return ret;
 }
@@ -1689,8 +1688,7 @@  test_hash_add_delete_2_jhash2(void)
 	ret = 0;
 
 fail_2_jhash2:
-	if (handle != NULL)
-		rte_hash_free(handle);
+	rte_hash_free(handle);
 
 	return ret;
 }
@@ -1754,8 +1752,7 @@  test_hash_add_delete_jhash_1word(void)
 	ret = 0;
 
 fail_jhash_1word:
-	if (handle != NULL)
-		rte_hash_free(handle);
+	rte_hash_free(handle);
 
 	return ret;
 }
@@ -1789,8 +1786,7 @@  test_hash_add_delete_jhash_2word(void)
 	ret = 0;
 
 fail_jhash_2word:
-	if (handle != NULL)
-		rte_hash_free(handle);
+	rte_hash_free(handle);
 
 	return ret;
 }
@@ -1824,8 +1820,7 @@  test_hash_add_delete_jhash_3word(void)
 	ret = 0;
 
 fail_jhash_3word:
-	if (handle != NULL)
-		rte_hash_free(handle);
+	rte_hash_free(handle);
 
 	return ret;
 }
diff --git a/app/test/test_hash_perf.c b/app/test/test_hash_perf.c
index 76cdac5d5320..287f486316f1 100644
--- a/app/test/test_hash_perf.c
+++ b/app/test/test_hash_perf.c
@@ -106,12 +106,7 @@  create_table(unsigned int with_data, unsigned int table_index,
 	ut_params.key_len = hashtest_key_lens[table_index];
 	ut_params.socket_id = rte_socket_id();
 	h[table_index] = rte_hash_find_existing(name);
-	if (h[table_index] != NULL)
-		/*
-		 * If table was already created, free it to create it again,
-		 * so we force it is empty
-		 */
-		rte_hash_free(h[table_index]);
+	rte_hash_free(h[table_index]);
 	h[table_index] = rte_hash_create(&ut_params);
 	if (h[table_index] == NULL) {
 		printf("Error creating table\n");
diff --git a/app/test/test_link_bonding.c b/app/test/test_link_bonding.c
index dc6fc46b9c93..82a9b8e01a82 100644
--- a/app/test/test_link_bonding.c
+++ b/app/test/test_link_bonding.c
@@ -1639,8 +1639,7 @@  test_roundrobin_rx_burst_on_single_slave(void)
 
 	/* free mbufs */
 	for (i = 0; i < MAX_PKT_BURST; i++) {
-		if (rx_pkt_burst[i] != NULL)
-			rte_pktmbuf_free(rx_pkt_burst[i]);
+		rte_pktmbuf_free(rx_pkt_burst[i]);
 	}
 
 
@@ -1722,8 +1721,7 @@  test_roundrobin_rx_burst_on_multiple_slaves(void)
 
 	/* free mbufs */
 	for (i = 0; i < MAX_PKT_BURST; i++) {
-		if (rx_pkt_burst[i] != NULL)
-			rte_pktmbuf_free(rx_pkt_burst[i]);
+		rte_pktmbuf_free(rx_pkt_burst[i]);
 	}
 
 	/* Clean up and remove slaves from bonded device */
@@ -2010,8 +2008,7 @@  test_roundrobin_verify_slave_link_status_change_behaviour(void)
 
 	/* free mbufs */
 	for (i = 0; i < MAX_PKT_BURST; i++) {
-		if (rx_pkt_burst[i] != NULL)
-			rte_pktmbuf_free(rx_pkt_burst[i]);
+		rte_pktmbuf_free(rx_pkt_burst[i]);
 	}
 
 	/* Clean up and remove slaves from bonded device */
diff --git a/app/test/test_link_bonding_mode4.c b/app/test/test_link_bonding_mode4.c
index 351129de2f9b..d9b9c323c7f8 100644
--- a/app/test/test_link_bonding_mode4.c
+++ b/app/test/test_link_bonding_mode4.c
@@ -194,8 +194,7 @@  free_pkts(struct rte_mbuf **pkts, uint16_t count)
 	uint16_t i;
 
 	for (i = 0; i < count; i++) {
-		if (pkts[i] != NULL)
-			rte_pktmbuf_free(pkts[i]);
+		rte_pktmbuf_free(pkts[i]);
 	}
 }
 
diff --git a/app/test/test_malloc.c b/app/test/test_malloc.c
index 6d9249f831be..d424d7808af3 100644
--- a/app/test/test_malloc.c
+++ b/app/test/test_malloc.c
@@ -812,7 +812,7 @@  test_zero_aligned_alloc(void)
 
 err_return:
 	/*clean up */
-	if (p1) rte_free(p1);
+	rte_free(p1);
 	return -1;
 }
 
@@ -865,8 +865,7 @@  test_malloc_bad_params(void)
 
 err_return:
 	/* clean up pointer */
-	if (bad_ptr)
-		rte_free(bad_ptr);
+	rte_free(bad_ptr);
 	return -1;
 }
 
diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c
index f54d1d7c006a..daebf09d44b7 100644
--- a/app/test/test_mbuf.c
+++ b/app/test/test_mbuf.c
@@ -304,8 +304,7 @@  test_one_pktmbuf(struct rte_mempool *pktmbuf_pool)
 	return 0;
 
 fail:
-	if (m)
-		rte_pktmbuf_free(m);
+	rte_pktmbuf_free(m);
 	return -1;
 }
 
@@ -416,12 +415,9 @@  testclone_testupdate_testdetach(struct rte_mempool *pktmbuf_pool,
 	return 0;
 
 fail:
-	if (m)
-		rte_pktmbuf_free(m);
-	if (clone)
-		rte_pktmbuf_free(clone);
-	if (clone2)
-		rte_pktmbuf_free(clone2);
+	rte_pktmbuf_free(m);
+	rte_pktmbuf_free(clone);
+	rte_pktmbuf_free(clone2);
 	return -1;
 }
 
@@ -572,12 +568,9 @@  test_pktmbuf_copy(struct rte_mempool *pktmbuf_pool,
 	return 0;
 
 fail:
-	if (m)
-		rte_pktmbuf_free(m);
-	if (copy)
-		rte_pktmbuf_free(copy);
-	if (copy2)
-		rte_pktmbuf_free(copy2);
+	rte_pktmbuf_free(m);
+	rte_pktmbuf_free(copy);
+	rte_pktmbuf_free(copy2);
 	return -1;
 }
 
@@ -679,12 +672,9 @@  test_attach_from_different_pool(struct rte_mempool *pktmbuf_pool,
 	return 0;
 
 fail:
-	if (m)
-		rte_pktmbuf_free(m);
-	if (clone)
-		rte_pktmbuf_free(clone);
-	if (clone2)
-		rte_pktmbuf_free(clone2);
+	rte_pktmbuf_free(m);
+	rte_pktmbuf_free(clone);
+	rte_pktmbuf_free(clone2);
 	return -1;
 }
 
@@ -722,8 +712,7 @@  test_pktmbuf_pool(struct rte_mempool *pktmbuf_pool)
 	}
 	/* free them */
 	for (i=0; i<NB_MBUF; i++) {
-		if (m[i] != NULL)
-			rte_pktmbuf_free(m[i]);
+		rte_pktmbuf_free(m[i]);
 	}
 
 	return ret;
@@ -924,8 +913,7 @@  test_pktmbuf_pool_ptr(struct rte_mempool *pktmbuf_pool)
 
 	/* free them */
 	for (i=0; i<NB_MBUF; i++) {
-		if (m[i] != NULL)
-			rte_pktmbuf_free(m[i]);
+		rte_pktmbuf_free(m[i]);
 	}
 
 	for (i=0; i<NB_MBUF; i++)
@@ -947,8 +935,7 @@  test_pktmbuf_pool_ptr(struct rte_mempool *pktmbuf_pool)
 
 	/* free them */
 	for (i=0; i<NB_MBUF; i++) {
-		if (m[i] != NULL)
-			rte_pktmbuf_free(m[i]);
+		rte_pktmbuf_free(m[i]);
 	}
 
 	return ret;
@@ -1355,8 +1342,7 @@  test_mbuf_linearize(struct rte_mempool *pktmbuf_pool, int pkt_len,
 	return 0;
 
 fail:
-	if (mbuf)
-		rte_pktmbuf_free(mbuf);
+	rte_pktmbuf_free(mbuf);
 	return -1;
 }
 
@@ -2772,8 +2758,7 @@  test_nb_segs_and_next_reset(void)
 	return 0;
 
 fail:
-	if (pool != NULL)
-		rte_mempool_free(pool);
+	rte_mempool_free(pool);
 	return -1;
 }
 
diff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c
index 34c5e1234695..320dacea3498 100644
--- a/app/test/test_pcapng.c
+++ b/app/test/test_pcapng.c
@@ -240,8 +240,7 @@  test_validate(void)
 static void
 test_cleanup(void)
 {
-	if (mp)
-		rte_mempool_free(mp);
+	rte_mempool_free(mp);
 
 	if (pcapng)
 		rte_pcapng_close(pcapng);
diff --git a/app/test/test_reorder.c b/app/test/test_reorder.c
index 1c4226da6501..962c31953f91 100644
--- a/app/test/test_reorder.c
+++ b/app/test/test_reorder.c
@@ -208,8 +208,7 @@  test_reorder_insert(void)
 exit:
 	rte_reorder_free(b);
 	for (i = 0; i < num_bufs; i++) {
-		if (bufs[i] != NULL)
-			rte_pktmbuf_free(bufs[i]);
+		rte_pktmbuf_free(bufs[i]);
 	}
 	return ret;
 }
@@ -268,8 +267,7 @@  test_reorder_drain(void)
 		ret = -1;
 		goto exit;
 	}
-	if (robufs[0] != NULL)
-		rte_pktmbuf_free(robufs[0]);
+	rte_pktmbuf_free(robufs[0]);
 
 	/* Insert more packets
 	 * RB[] = {NULL, NULL, NULL, NULL}
@@ -303,8 +301,7 @@  test_reorder_drain(void)
 		goto exit;
 	}
 	for (i = 0; i < 3; i++) {
-		if (robufs[i] != NULL)
-			rte_pktmbuf_free(robufs[i]);
+		rte_pktmbuf_free(robufs[i]);
 	}
 
 	/*
@@ -322,10 +319,8 @@  test_reorder_drain(void)
 exit:
 	rte_reorder_free(b);
 	for (i = 0; i < num_bufs; i++) {
-		if (bufs[i] != NULL)
-			rte_pktmbuf_free(bufs[i]);
-		if (robufs[i] != NULL)
-			rte_pktmbuf_free(robufs[i]);
+		rte_pktmbuf_free(bufs[i]);
+		rte_pktmbuf_free(robufs[i]);
 	}
 	return ret;
 }
diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c
index 3d2793852049..cd4611ab48df 100644
--- a/app/test/virtual_pmd.c
+++ b/app/test/virtual_pmd.c
@@ -397,8 +397,7 @@  virtual_ethdev_tx_burst_fail(void *queue, struct rte_mbuf **bufs,
 		/* free packets in burst */
 		for (i = 0; i < successfully_txd; i++) {
 			/* free packets in burst */
-			if (bufs[i] != NULL)
-				rte_pktmbuf_free(bufs[i]);
+			rte_pktmbuf_free(bufs[i]);
 
 			bufs[i] = NULL;
 		}