From: David Marchand <david.marchand@6wind.com>
To: dev@dpdk.org
Cc: viktorin@rehivetech.com
Subject: [dpdk-dev] [PATCH v2 2/2] ethdev: move code to common place in hotplug
Date: Fri, 22 Jan 2016 15:06:58 +0100 [thread overview]
Message-ID: <1453471618-29722-3-git-send-email-david.marchand@6wind.com> (raw)
In-Reply-To: <1453471618-29722-1-git-send-email-david.marchand@6wind.com>
Move these error logs and checks on detach capabilities in a common place.
Signed-off-by: David Marchand <david.marchand@6wind.com>
---
Changes since v1:
- restore EINVAL error code for rte_eth_dev_(at|de)tach
lib/librte_ether/rte_ethdev.c | 77 ++++++++++++++++++++++++++-----------------
1 file changed, 46 insertions(+), 31 deletions(-)
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index cab74e0..a45563d 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -514,7 +514,6 @@ rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
return 0;
err:
- RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
return -1;
}
@@ -525,10 +524,6 @@ rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
struct rte_pci_addr freed_addr;
struct rte_pci_addr vp;
- /* check whether the driver supports detach feature, or not */
- if (rte_eth_dev_is_detachable(port_id))
- goto err;
-
/* get pci address by port id */
if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
goto err;
@@ -546,7 +541,6 @@ rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
*addr = freed_addr;
return 0;
err:
- RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
return -1;
}
@@ -579,8 +573,6 @@ end:
if (args)
free(args);
- if (ret < 0)
- RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
return ret;
}
@@ -590,10 +582,6 @@ rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
{
char name[RTE_ETH_NAME_MAX_LEN];
- /* check whether the driver supports detach feature, or not */
- if (rte_eth_dev_is_detachable(port_id))
- goto err;
-
/* get device name by port id */
if (rte_eth_dev_get_name_by_port(port_id, name))
goto err;
@@ -605,7 +593,6 @@ rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
strncpy(vdevname, name, sizeof(name));
return 0;
err:
- RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
return -1;
}
@@ -614,14 +601,27 @@ int
rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
{
struct rte_pci_addr addr;
+ int ret = -1;
- if ((devargs == NULL) || (port_id == NULL))
- return -EINVAL;
+ if ((devargs == NULL) || (port_id == NULL)) {
+ ret = -EINVAL;
+ goto err;
+ }
- if (eal_parse_pci_DomBDF(devargs, &addr) == 0)
- return rte_eth_dev_attach_pdev(&addr, port_id);
- else
- return rte_eth_dev_attach_vdev(devargs, port_id);
+ if (eal_parse_pci_DomBDF(devargs, &addr) == 0) {
+ ret = rte_eth_dev_attach_pdev(&addr, port_id);
+ if (ret < 0)
+ goto err;
+ } else {
+ ret = rte_eth_dev_attach_vdev(devargs, port_id);
+ if (ret < 0)
+ goto err;
+ }
+
+ return 0;
+err:
+ RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
+ return ret;
}
/* detach the device, then store the name of the device */
@@ -629,26 +629,41 @@ int
rte_eth_dev_detach(uint8_t port_id, char *name)
{
struct rte_pci_addr addr;
- int ret;
+ int ret = -1;
- if (name == NULL)
- return -EINVAL;
+ if (name == NULL) {
+ ret = -EINVAL;
+ goto err;
+ }
+
+ /* check whether the driver supports detach feature, or not */
+ if (rte_eth_dev_is_detachable(port_id))
+ goto err;
if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
if (ret < 0)
- return ret;
+ goto err;
ret = rte_eth_dev_detach_pdev(port_id, &addr);
- if (ret == 0)
- snprintf(name, RTE_ETH_NAME_MAX_LEN,
- "%04x:%02x:%02x.%d",
- addr.domain, addr.bus,
- addr.devid, addr.function);
+ if (ret < 0)
+ goto err;
- return ret;
- } else
- return rte_eth_dev_detach_vdev(port_id, name);
+ snprintf(name, RTE_ETH_NAME_MAX_LEN,
+ "%04x:%02x:%02x.%d",
+ addr.domain, addr.bus,
+ addr.devid, addr.function);
+ } else {
+ ret = rte_eth_dev_detach_vdev(port_id, name);
+ if (ret < 0)
+ goto err;
+ }
+
+ return 0;
+
+err:
+ RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
+ return ret;
}
static int
--
1.9.1
next prev parent reply other threads:[~2016-01-22 14:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-21 11:57 [dpdk-dev] [PATCH 0/2] minor cleanup in ethdev hotplug David Marchand
2016-01-21 11:57 ` [dpdk-dev] [PATCH 1/2] ethdev: remove useless null checks David Marchand
2016-01-21 19:02 ` [dpdk-dev] [dpdk-dev,1/2] " Jan Viktorin
2016-01-22 9:11 ` Thomas Monjalon
2016-01-21 11:57 ` [dpdk-dev] [PATCH 2/2] ethdev: move code to common place in hotplug David Marchand
2016-01-21 15:38 ` [dpdk-dev] [dpdk-dev, " Jan Viktorin
2016-01-21 18:06 ` David Marchand
2016-01-21 18:42 ` Thomas Monjalon
2016-01-22 7:15 ` David Marchand
2016-01-22 14:06 ` [dpdk-dev] [PATCH v2 0/2] minor cleanup in ethdev hotplug David Marchand
2016-01-22 14:06 ` [dpdk-dev] [PATCH v2 1/2] ethdev: remove useless null checks David Marchand
2016-01-26 15:50 ` Jan Viktorin
2016-01-27 9:40 ` David Marchand
2016-01-22 14:06 ` David Marchand [this message]
2016-01-26 15:48 ` [dpdk-dev] [PATCH v2 2/2] ethdev: move code to common place in hotplug Jan Viktorin
2016-01-27 15:10 ` [dpdk-dev] [PATCH v2 0/2] minor cleanup in ethdev hotplug 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=1453471618-29722-3-git-send-email-david.marchand@6wind.com \
--to=david.marchand@6wind.com \
--cc=dev@dpdk.org \
--cc=viktorin@rehivetech.com \
/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).