[PATCH v3 36/36] other: remove unnecessary NULL checks
Stephen Hemminger
stephen at networkplumber.org
Wed Feb 9 20:17:48 CET 2022
Remove redundant NULL pointer checks before free functions
found by nullfree.cocci
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
Acked-by: David Hunt <david.hunt at 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(-)
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]);
}
}
--
2.34.1
More information about the dev
mailing list