All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH 2/7] ethdev: reduce goto's in attach/detach
Date: Mon,  9 Jan 2017 15:30:17 -0800	[thread overview]
Message-ID: <20170109233022.31154-3-stephen@networkplumber.org> (raw)
In-Reply-To: <20170109233022.31154-1-stephen@networkplumber.org>

Extra goto's to just a return are unnecessary.
Don't do unnecessary initialization. Propgate return value.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_ether/rte_ethdev.c | 52 +++++++++++++++++--------------------------
 1 file changed, 21 insertions(+), 31 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 9dea1f15..2bd7db6d 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -419,18 +419,17 @@ rte_eth_dev_is_detachable(uint8_t port_id)
 int
 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
 {
-	int ret = -1;
 	int current = rte_eth_dev_count();
 	char *name = NULL;
 	char *args = NULL;
+	int ret;
 
-	if ((devargs == NULL) || (port_id == NULL)) {
-		ret = -EINVAL;
-		goto err;
-	}
+	if (devargs == NULL || port_id == NULL)
+		return -EINVAL;
 
 	/* parse devargs, then retrieve device name and args */
-	if (rte_eal_parse_devargs_str(devargs, &name, &args))
+	ret = rte_eal_parse_devargs_str(devargs, &name, &args);
+	if (ret < 0)
 		goto err;
 
 	ret = rte_eal_dev_attach(name, args);
@@ -441,20 +440,18 @@ rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
 	if (!rte_eth_dev_count()) {
 		RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
 		ret = -1;
-		goto err;
-	}
-
-	/* if nothing happened, there is a bug here, since some driver told us
-	 * it did attach a device, but did not create a port.
-	 */
-	if (current == rte_eth_dev_count()) {
+	} else if (current == rte_eth_dev_count()) {
+		/*
+		 * if nothing happened, there is a bug here, since
+		 * some driver told us it did attach a device, but did
+		 * not create a port.
+		 */
 		ret = -1;
-		goto err;
+	} else {
+		*port_id = eth_dev_last_created_port;
+		ret = 0;
 	}
 
-	*port_id = eth_dev_last_created_port;
-	ret = 0;
-
 err:
 	free(name);
 	free(args);
@@ -465,27 +462,20 @@ rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
 int
 rte_eth_dev_detach(uint8_t port_id, char *name)
 {
-	int ret = -1;
+	int ret;
 
-	if (name == NULL) {
-		ret = -EINVAL;
-		goto err;
-	}
+	if (name == NULL)
+		return -EINVAL;
 
 	/* FIXME: move this to eal, once device flags are relocated there */
-	if (rte_eth_dev_is_detachable(port_id))
-		goto err;
+	ret = rte_eth_dev_is_detachable(port_id);
+	if (ret < 0)
+		return ret;
 
 	snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
 		 "%s", rte_eth_devices[port_id].data->name);
-	ret = rte_eal_dev_detach(name);
-	if (ret < 0)
-		goto err;
 
-	return 0;
-
-err:
-	return ret;
+	return rte_eal_dev_detach(name);
 }
 
 static int
-- 
2.11.0

  parent reply	other threads:[~2017-01-09 23:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-09 23:30 [PATCH v2 0/7] minor cleanup Stephen Hemminger
2017-01-09 23:30 ` [PATCH 1/7] bonding, malloc, bitmap: remove useless return Stephen Hemminger
2017-01-09 23:30 ` Stephen Hemminger [this message]
2017-01-10  8:40   ` [PATCH 2/7] ethdev: reduce goto's in attach/detach Thomas Monjalon
2017-02-01 17:26     ` Ferruh Yigit
2017-01-09 23:30 ` [PATCH 3/7] bnx2x: remove useless return's Stephen Hemminger
2017-01-09 23:30 ` [PATCH 4/7] kni: remove useless return statements Stephen Hemminger
2017-01-11 17:36   ` Ferruh Yigit
2017-01-09 23:30 ` [PATCH 5/7] i40e: remove useless return Stephen Hemminger
2017-01-09 23:30 ` [PATCH 6/7] ixgbe: " Stephen Hemminger
2017-02-01 16:40   ` Ananyev, Konstantin
2017-02-08 14:43     ` Dai, Wei
2017-01-09 23:30 ` [PATCH 7/7] igb: remove useless return's Stephen Hemminger

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=20170109233022.31154-3-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.