DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v2 4/6] pmd: remove unnecessary if() before rte_free
Date: Tue,  7 Apr 2015 14:21:01 -0700	[thread overview]
Message-ID: <1428441663-3825-4-git-send-email-stephen@networkplumber.org> (raw)
In-Reply-To: <1428441663-3825-1-git-send-email-stephen@networkplumber.org>

Since rte_free accept NULL and does nothing, better to save
space and remove these useless checks.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_pmd_af_packet/rte_eth_af_packet.c | 14 ++++++--------
 lib/librte_pmd_bond/rte_eth_bond_api.c       | 13 +++++--------
 lib/librte_pmd_enic/enic_main.c              |  3 +--
 lib/librte_pmd_mlx4/mlx4.c                   | 15 +++++++--------
 lib/librte_pmd_null/rte_eth_null.c           | 13 +++++--------
 lib/librte_pmd_pcap/rte_eth_pcap.c           | 11 +++++------
 lib/librte_pmd_ring/rte_eth_ring.c           | 10 ++++------
 lib/librte_pmd_xenvirt/rte_eth_xenvirt.c     | 10 ++++------
 8 files changed, 37 insertions(+), 52 deletions(-)

diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
index 2ac50ba..c10da6c 100644
--- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c
+++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
@@ -680,18 +680,16 @@ rte_pmd_init_internals(const char *name,
 	return 0;
 
 error:
-	if (data)
-		rte_free(data);
-	if (pci_dev)
-		rte_free(pci_dev);
+	rte_free(data);
+	rte_free(pci_dev);
+
 	if (*internals) {
 		for (q = 0; q < nb_queues; q++) {
 			munmap((*internals)->rx_queue[q].map,
 			       2 * req->tp_block_size * req->tp_block_nr);
-			if ((*internals)->rx_queue[q].rd)
-				rte_free((*internals)->rx_queue[q].rd);
-			if ((*internals)->tx_queue[q].rd)
-				rte_free((*internals)->tx_queue[q].rd);
+
+			rte_free((*internals)->rx_queue[q].rd);
+			rte_free((*internals)->tx_queue[q].rd);
 			if (((*internals)->rx_queue[q].sockfd != 0) &&
 				((*internals)->rx_queue[q].sockfd != qsockfd))
 				close((*internals)->rx_queue[q].sockfd);
diff --git a/lib/librte_pmd_bond/rte_eth_bond_api.c b/lib/librte_pmd_bond/rte_eth_bond_api.c
index 13f3941..f594fe1 100644
--- a/lib/librte_pmd_bond/rte_eth_bond_api.c
+++ b/lib/librte_pmd_bond/rte_eth_bond_api.c
@@ -318,14 +318,11 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
 	return eth_dev->data->port_id;
 
 err:
-	if (pci_dev)
-		rte_free(pci_dev);
-	if (pci_id_table)
-		rte_free(pci_id_table);
-	if (eth_drv)
-		rte_free(eth_drv);
-	if (internals)
-		rte_free(internals);
+	rte_free(pci_dev);
+	rte_free(pci_id_table);
+	rte_free(eth_drv);
+	rte_free(internals);
+
 	return -1;
 }
 
diff --git a/lib/librte_pmd_enic/enic_main.c b/lib/librte_pmd_enic/enic_main.c
index 0892b3e..0e40d46 100644
--- a/lib/librte_pmd_enic/enic_main.c
+++ b/lib/librte_pmd_enic/enic_main.c
@@ -983,8 +983,7 @@ static void enic_dev_deinit(struct enic *enic)
 {
 	struct rte_eth_dev *eth_dev = enic->rte_dev;
 
-	if (eth_dev->data->mac_addrs)
-		rte_free(eth_dev->data->mac_addrs);
+	rte_free(eth_dev->data->mac_addrs);
 }
 
 
diff --git a/lib/librte_pmd_mlx4/mlx4.c b/lib/librte_pmd_mlx4/mlx4.c
index fa749f4..0eca322 100644
--- a/lib/librte_pmd_mlx4/mlx4.c
+++ b/lib/librte_pmd_mlx4/mlx4.c
@@ -792,10 +792,10 @@ txq_alloc_elts(struct txq *txq, unsigned int elts_n)
 error:
 	if (mr_linear != NULL)
 		claim_zero(ibv_dereg_mr(mr_linear));
-	if (elts_linear != NULL)
-		rte_free(elts_linear);
-	if (elts != NULL)
-		rte_free(elts);
+
+	rte_free(elts_linear);
+	rte_free(elts);
+
 	DEBUG("%p: failed, freed everything", (void *)txq);
 	assert(ret > 0);
 	return ret;
@@ -823,8 +823,8 @@ txq_free_elts(struct txq *txq)
 	txq->mr_linear = NULL;
 	if (mr_linear != NULL)
 		claim_zero(ibv_dereg_mr(mr_linear));
-	if (elts_linear != NULL)
-		rte_free(elts_linear);
+
+	rte_free(elts_linear);
 	if (elts == NULL)
 		return;
 	for (i = 0; (i != elemof(*elts)); ++i) {
@@ -4602,8 +4602,7 @@ mlx4_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 		continue;
 
 port_error:
-		if (priv)
-			rte_free(priv);
+		rte_free(priv);
 		if (pd)
 			claim_zero(ibv_dealloc_pd(pd));
 		if (ctx)
diff --git a/lib/librte_pmd_null/rte_eth_null.c b/lib/librte_pmd_null/rte_eth_null.c
index 0e18502..036faaf 100644
--- a/lib/librte_pmd_null/rte_eth_null.c
+++ b/lib/librte_pmd_null/rte_eth_null.c
@@ -355,8 +355,7 @@ eth_queue_release(void *q)
 		return;
 
 	nq = q;
-	if (nq->dummy_packet)
-		rte_free(nq->dummy_packet);
+	rte_free(nq->dummy_packet);
 }
 
 static int
@@ -458,12 +457,10 @@ eth_dev_null_create(const char *name,
 	return 0;
 
 error:
-	if (data)
-		rte_free(data);
-	if (pci_dev)
-		rte_free(pci_dev);
-	if (internals)
-		rte_free(internals);
+	rte_free(data);
+	rte_free(pci_dev);
+	rte_free(internals);
+
 	return -1;
 }
 
diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_eth_pcap.c
index 204ae68..3a7db98 100644
--- a/lib/librte_pmd_pcap/rte_eth_pcap.c
+++ b/lib/librte_pmd_pcap/rte_eth_pcap.c
@@ -760,12 +760,11 @@ rte_pmd_init_internals(const char *name, const unsigned nb_rx_queues,
 
 	return 0;
 
-	error: if (data)
-		rte_free(data);
-	if (pci_dev)
-		rte_free(pci_dev);
-	if (*internals)
-		rte_free(*internals);
+error: 
+	rte_free(data);
+	rte_free(pci_dev);
+	rte_free(*internals);
+
 	return -1;
 }
 
diff --git a/lib/librte_pmd_ring/rte_eth_ring.c b/lib/librte_pmd_ring/rte_eth_ring.c
index 1e66d4e..199e15f 100644
--- a/lib/librte_pmd_ring/rte_eth_ring.c
+++ b/lib/librte_pmd_ring/rte_eth_ring.c
@@ -349,12 +349,10 @@ rte_eth_from_rings(const char *name, struct rte_ring *const rx_queues[],
 	return 0;
 
 error:
-	if (data)
-		rte_free(data);
-	if (pci_dev)
-		rte_free(pci_dev);
-	if (internals)
-		rte_free(internals);
+	rte_free(data);
+	rte_free(pci_dev);
+	rte_free(internals);
+
 	return -1;
 }
 
diff --git a/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c b/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c
index bc403d6..edf2a5f 100644
--- a/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c
+++ b/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c
@@ -679,12 +679,10 @@ eth_dev_xenvirt_create(const char *name, const char *params,
 	return 0;
 
 err:
-	if (data)
-		rte_free(data);
-	if (pci_dev)
-		rte_free(pci_dev);
-	if (internals)
-		rte_free(internals);
+	rte_free(data);
+	rte_free(pci_dev);
+	rte_free(internals);
+
 	return -1;
 }
 
-- 
2.1.4

  parent reply	other threads:[~2015-04-07 21:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-07 21:20 [dpdk-dev] [PATCH v2 1/6] test: remove useless memset Stephen Hemminger
2015-04-07 21:20 ` [dpdk-dev] [PATCH v2 2/6] test: remove useless check of NULL before rte_free Stephen Hemminger
2015-04-07 21:21 ` [dpdk-dev] [PATCH v2 3/6] examples: get rid of unneeded null checks " Stephen Hemminger
2015-04-07 21:21 ` Stephen Hemminger [this message]
2015-04-07 21:21 ` [dpdk-dev] [PATCH v2 5/6] test: put dev_ops in private Stephen Hemminger
2015-04-07 21:21 ` [dpdk-dev] [PATCH v2 6/6] eth: make dev_ops const Stephen Hemminger
2015-04-08 11:49 ` [dpdk-dev] [PATCH v2 1/6] test: remove useless memset Neil Horman
2015-04-13 20:36   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1428441663-3825-4-git-send-email-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).