[v3,36/36] other: remove unnecessary NULL checks

Message ID 20220209191748.377729-37-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series remove unnecessary null checks |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Stephen Hemminger Feb. 9, 2022, 7:17 p.m. UTC
  Remove redundant NULL pointer checks before free functions
found by nullfree.cocci

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: David Hunt <david.hunt@intel.com>
---
 lib/graph/graph_stats.c          |  3 +--
 lib/ipsec/ipsec_sad.c            |  3 +--
 lib/port/rte_port_source_sink.c  | 21 +++++++--------------
 lib/power/rte_power_empty_poll.c |  3 +--
 lib/reorder/rte_reorder.c        |  6 ++----
 5 files changed, 12 insertions(+), 24 deletions(-)
  

Patch

diff --git a/lib/graph/graph_stats.c b/lib/graph/graph_stats.c
index aa70929dc32e..65e12d46a313 100644
--- a/lib/graph/graph_stats.c
+++ b/lib/graph/graph_stats.c
@@ -233,8 +233,7 @@  cluster_add(struct cluster *cluster, struct graph *graph)
 static void
 cluster_fini(struct cluster *cluster)
 {
-	if (cluster->graphs)
-		free(cluster->graphs);
+	free(cluster->graphs);
 }
 
 static int
diff --git a/lib/ipsec/ipsec_sad.c b/lib/ipsec/ipsec_sad.c
index 531e1e323cdc..af4b1ce757d2 100644
--- a/lib/ipsec/ipsec_sad.c
+++ b/lib/ipsec/ipsec_sad.c
@@ -440,8 +440,7 @@  rte_ipsec_sad_destroy(struct rte_ipsec_sad *sad)
 	rte_hash_free(sad->hash[RTE_IPSEC_SAD_SPI_DIP]);
 	rte_hash_free(sad->hash[RTE_IPSEC_SAD_SPI_DIP_SIP]);
 	rte_free(sad);
-	if (te != NULL)
-		rte_free(te);
+	rte_free(te);
 }
 
 /*
diff --git a/lib/port/rte_port_source_sink.c b/lib/port/rte_port_source_sink.c
index 68575c98338d..79042d13ff66 100644
--- a/lib/port/rte_port_source_sink.c
+++ b/lib/port/rte_port_source_sink.c
@@ -163,14 +163,10 @@  pcap_source_load(struct rte_port_source *port,
 	return 0;
 
 error_exit:
-	if (pkt_len_aligns)
-		rte_free(pkt_len_aligns);
-	if (port->pkt_len)
-		rte_free(port->pkt_len);
-	if (port->pkts)
-		rte_free(port->pkts);
-	if (port->pkt_buff)
-		rte_free(port->pkt_buff);
+	rte_free(pkt_len_aligns);
+	rte_free(port->pkt_len);
+	rte_free(port->pkts);
+	rte_free(port->pkt_buff);
 
 	return -1;
 }
@@ -242,12 +238,9 @@  rte_port_source_free(void *port)
 	if (p == NULL)
 		return 0;
 
-	if (p->pkt_len)
-		rte_free(p->pkt_len);
-	if (p->pkts)
-		rte_free(p->pkts);
-	if (p->pkt_buff)
-		rte_free(p->pkt_buff);
+	rte_free(p->pkt_len);
+	rte_free(p->pkts);
+	rte_free(p->pkt_buff);
 
 	rte_free(p);
 
diff --git a/lib/power/rte_power_empty_poll.c b/lib/power/rte_power_empty_poll.c
index c4b5de9601cf..2261ce7820f6 100644
--- a/lib/power/rte_power_empty_poll.c
+++ b/lib/power/rte_power_empty_poll.c
@@ -457,8 +457,7 @@  rte_power_empty_poll_stat_free(void)
 
 	RTE_LOG(INFO, POWER, "Close the Empty Poll\n");
 
-	if (ep_params != NULL)
-		rte_free(ep_params);
+	rte_free(ep_params);
 }
 
 int
diff --git a/lib/reorder/rte_reorder.c b/lib/reorder/rte_reorder.c
index 9445853b79cc..bc0241bfb3fd 100644
--- a/lib/reorder/rte_reorder.c
+++ b/lib/reorder/rte_reorder.c
@@ -192,10 +192,8 @@  rte_reorder_free_mbufs(struct rte_reorder_buffer *b)
 
 	/* Free up the mbufs of order buffer & ready buffer */
 	for (i = 0; i < b->order_buf.size; i++) {
-		if (b->order_buf.entries[i])
-			rte_pktmbuf_free(b->order_buf.entries[i]);
-		if (b->ready_buf.entries[i])
-			rte_pktmbuf_free(b->ready_buf.entries[i]);
+		rte_pktmbuf_free(b->order_buf.entries[i]);
+		rte_pktmbuf_free(b->ready_buf.entries[i]);
 	}
 }