[v3,22/36] net/i*: remove unnecessary NULL checks

Message ID 20220209191748.377729-23-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

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: Haiyue Wang <haiyue.wang@intel.com>
---
 drivers/net/i40e/i40e_ethdev.c    | 27 +++++++++------------------
 drivers/net/i40e/i40e_rxtx.c      |  3 +--
 drivers/net/iavf/iavf_rxtx.c      |  3 +--
 drivers/net/ice/ice_fdir_filter.c |  6 ++----
 drivers/net/igc/igc_flow.c        |  5 +----
 drivers/net/ixgbe/ixgbe_ethdev.c  | 12 ++++--------
 drivers/net/ixgbe/ixgbe_rxtx.c    |  3 +--
 7 files changed, 19 insertions(+), 40 deletions(-)
  

Patch

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 1d417dbf8ad7..ecfa3c94db44 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -1781,10 +1781,8 @@  i40e_rm_ethtype_filter_list(struct i40e_pf *pf)
 
 	ethertype_rule = &pf->ethertype;
 	/* Remove all ethertype filter rules and hash */
-	if (ethertype_rule->hash_map)
-		rte_free(ethertype_rule->hash_map);
-	if (ethertype_rule->hash_table)
-		rte_hash_free(ethertype_rule->hash_table);
+	rte_free(ethertype_rule->hash_map);
+	rte_hash_free(ethertype_rule->hash_table);
 
 	while ((p_ethertype = TAILQ_FIRST(&ethertype_rule->ethertype_list))) {
 		TAILQ_REMOVE(&ethertype_rule->ethertype_list,
@@ -1801,10 +1799,8 @@  i40e_rm_tunnel_filter_list(struct i40e_pf *pf)
 
 	tunnel_rule = &pf->tunnel;
 	/* Remove all tunnel director rules and hash */
-	if (tunnel_rule->hash_map)
-		rte_free(tunnel_rule->hash_map);
-	if (tunnel_rule->hash_table)
-		rte_hash_free(tunnel_rule->hash_table);
+	rte_free(tunnel_rule->hash_map);
+	rte_hash_free(tunnel_rule->hash_table);
 
 	while ((p_tunnel = TAILQ_FIRST(&tunnel_rule->tunnel_list))) {
 		TAILQ_REMOVE(&tunnel_rule->tunnel_list, p_tunnel, rules);
@@ -1833,16 +1829,11 @@  i40e_fdir_memory_cleanup(struct i40e_pf *pf)
 	fdir_info = &pf->fdir;
 
 	/* flow director memory cleanup */
-	if (fdir_info->hash_map)
-		rte_free(fdir_info->hash_map);
-	if (fdir_info->hash_table)
-		rte_hash_free(fdir_info->hash_table);
-	if (fdir_info->fdir_flow_pool.bitmap)
-		rte_free(fdir_info->fdir_flow_pool.bitmap);
-	if (fdir_info->fdir_flow_pool.pool)
-		rte_free(fdir_info->fdir_flow_pool.pool);
-	if (fdir_info->fdir_filter_array)
-		rte_free(fdir_info->fdir_filter_array);
+	rte_free(fdir_info->hash_map);
+	rte_hash_free(fdir_info->hash_table);
+	rte_free(fdir_info->fdir_flow_pool.bitmap);
+	rte_free(fdir_info->fdir_flow_pool.pool);
+	rte_free(fdir_info->fdir_filter_array);
 }
 
 void i40e_flex_payload_reg_set_default(struct i40e_hw *hw)
diff --git a/drivers/net/i40e/i40e_rxtx.c b/drivers/net/i40e/i40e_rxtx.c
index 9a00a9b71e2c..25a28ecea22c 100644
--- a/drivers/net/i40e/i40e_rxtx.c
+++ b/drivers/net/i40e/i40e_rxtx.c
@@ -2573,8 +2573,7 @@  i40e_reset_rx_queue(struct i40e_rx_queue *rxq)
 	rxq->rx_tail = 0;
 	rxq->nb_rx_hold = 0;
 
-	if (rxq->pkt_first_seg != NULL)
-		rte_pktmbuf_free(rxq->pkt_first_seg);
+	rte_pktmbuf_free(rxq->pkt_first_seg);
 
 	rxq->pkt_first_seg = NULL;
 	rxq->pkt_last_seg = NULL;
diff --git a/drivers/net/iavf/iavf_rxtx.c b/drivers/net/iavf/iavf_rxtx.c
index 94819e59b220..715893864349 100644
--- a/drivers/net/iavf/iavf_rxtx.c
+++ b/drivers/net/iavf/iavf_rxtx.c
@@ -230,8 +230,7 @@  reset_rx_queue(struct iavf_rx_queue *rxq)
 	rxq->rx_tail = 0;
 	rxq->nb_rx_hold = 0;
 
-	if (rxq->pkt_first_seg != NULL)
-		rte_pktmbuf_free(rxq->pkt_first_seg);
+	rte_pktmbuf_free(rxq->pkt_first_seg);
 
 	rxq->pkt_first_seg = NULL;
 	rxq->pkt_last_seg = NULL;
diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index 287032a6a739..b8728fb1be0b 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -421,10 +421,8 @@  ice_fdir_release_filter_list(struct ice_pf *pf)
 {
 	struct ice_fdir_info *fdir_info = &pf->fdir;
 
-	if (fdir_info->hash_map)
-		rte_free(fdir_info->hash_map);
-	if (fdir_info->hash_table)
-		rte_hash_free(fdir_info->hash_table);
+	rte_free(fdir_info->hash_map);
+	rte_hash_free(fdir_info->hash_table);
 
 	fdir_info->hash_map = NULL;
 	fdir_info->hash_table = NULL;
diff --git a/drivers/net/igc/igc_flow.c b/drivers/net/igc/igc_flow.c
index 66053060af5a..58a6a8a539c6 100644
--- a/drivers/net/igc/igc_flow.c
+++ b/drivers/net/igc/igc_flow.c
@@ -775,10 +775,7 @@  igc_flow_create(struct rte_eth_dev *dev,
 	}
 
 	if (ret) {
-		/* check and free the memory */
-		if (flow)
-			rte_free(flow);
-
+		rte_free(flow);
 		rte_flow_error_set(error, -ret,
 				RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
 				"Failed to create flow.");
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index c8f0460440c0..d7efe5c6d753 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -1322,10 +1322,8 @@  static int ixgbe_fdir_filter_uninit(struct rte_eth_dev *eth_dev)
 		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(eth_dev->data->dev_private);
 	struct ixgbe_fdir_filter *fdir_filter;
 
-		if (fdir_info->hash_map)
-		rte_free(fdir_info->hash_map);
-	if (fdir_info->hash_handle)
-		rte_hash_free(fdir_info->hash_handle);
+	rte_free(fdir_info->hash_map);
+	rte_hash_free(fdir_info->hash_handle);
 
 	while ((fdir_filter = TAILQ_FIRST(&fdir_info->fdir_list))) {
 		TAILQ_REMOVE(&fdir_info->fdir_list,
@@ -1343,10 +1341,8 @@  static int ixgbe_l2_tn_filter_uninit(struct rte_eth_dev *eth_dev)
 		IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(eth_dev->data->dev_private);
 	struct ixgbe_l2_tn_filter *l2_tn_filter;
 
-	if (l2_tn_info->hash_map)
-		rte_free(l2_tn_info->hash_map);
-	if (l2_tn_info->hash_handle)
-		rte_hash_free(l2_tn_info->hash_handle);
+	rte_free(l2_tn_info->hash_map);
+	rte_hash_free(l2_tn_info->hash_handle);
 
 	while ((l2_tn_filter = TAILQ_FIRST(&l2_tn_info->l2_tn_list))) {
 		TAILQ_REMOVE(&l2_tn_info->l2_tn_list,
diff --git a/drivers/net/ixgbe/ixgbe_rxtx.c b/drivers/net/ixgbe/ixgbe_rxtx.c
index 99e928a2a971..9e8ea366a506 100644
--- a/drivers/net/ixgbe/ixgbe_rxtx.c
+++ b/drivers/net/ixgbe/ixgbe_rxtx.c
@@ -2983,8 +2983,7 @@  ixgbe_reset_rx_queue(struct ixgbe_adapter *adapter, struct ixgbe_rx_queue *rxq)
 	rxq->rx_tail = 0;
 	rxq->nb_rx_hold = 0;
 
-	if (rxq->pkt_first_seg != NULL)
-		rte_pktmbuf_free(rxq->pkt_first_seg);
+	rte_pktmbuf_free(rxq->pkt_first_seg);
 
 	rxq->pkt_first_seg = NULL;
 	rxq->pkt_last_seg = NULL;