[dpdk-dev,2/7] ethdev: reduce goto's in attach/detach
Checks
Commit Message
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(-)
Comments
Hi Stephen,
Please use --in-reply-to to keep v1 and v2 in the same thread.
Comment below
2017-01-09 15:30, Stephen Hemminger:
> 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;
As commented on v1 by Ferruh and I, you should check also positive value.
>
> 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);
> }
On 1/10/2017 8:40 AM, Thomas Monjalon wrote:
> Hi Stephen,
>
> Please use --in-reply-to to keep v1 and v2 in the same thread.
>
> Comment below
>
>
> 2017-01-09 15:30, Stephen Hemminger:
>> 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;
>
> As commented on v1 by Ferruh and I, you should check also positive value.
In case it is not obvious, this patchset is stuck because of above
change request not addressed.
>
>>
>> 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);
>> }
>
@@ -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