]> git.droids-corp.org - dpdk.git/commitdiff
eal: fix positive error codes from probe/remove
authorIlya Maximets <i.maximets@samsung.com>
Thu, 6 Jun 2019 10:02:28 +0000 (13:02 +0300)
committerThomas Monjalon <thomas@monjalon.net>
Sat, 29 Jun 2019 19:28:38 +0000 (21:28 +0200)
According to API, 'rte_dev_probe()' and 'rte_dev_remove()' must
return 0 or negative error code. Bus code returns positive values
if device wasn't recognized by any driver, so the result of
'bus->plug/unplug()' must be converted. 'local_dev_probe()' and
'local_dev_remove()' also has their internal API, so the conversion
should be done there.

Positive on remove means that device not found by driver.
Positive on probe means that there are no suitable buses/drivers,
i.e. device is not supported.

Users of these API fixed to provide a good example by respecting
DPDK API. This also will allow to catch such issues in the future.

Fixes: a3ee360f4440 ("eal: add hotplug add/remove device")
Fixes: 244d5130719c ("eal: enable hotplug on multi-process")
Cc: stable@dpdk.org
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
app/test-pmd/testpmd.c
drivers/net/failsafe/failsafe.c
drivers/net/failsafe/failsafe_eal.c
drivers/net/failsafe/failsafe_ether.c
drivers/net/vdev_netvsc/vdev_netvsc.c
lib/librte_eal/common/eal_common_dev.c

index 0dd47b3e0350777c9f35062779acfb356b317735..c578f75e7738ccf241a4fe92146e6104cca30f0d 100644 (file)
@@ -2383,7 +2383,7 @@ attach_port(char *identifier)
                return;
        }
 
-       if (rte_dev_probe(identifier) != 0) {
+       if (rte_dev_probe(identifier) < 0) {
                TESTPMD_LOG(ERR, "Failed to attach port %s\n", identifier);
                return;
        }
@@ -2453,7 +2453,7 @@ detach_port_device(portid_t port_id)
                        port_flow_flush(port_id);
        }
 
-       if (rte_dev_remove(dev) != 0) {
+       if (rte_dev_remove(dev) < 0) {
                TESTPMD_LOG(ERR, "Failed to detach device %s\n", dev->name);
                return;
        }
index e91c274d8059a7178607572cb4be8623df94dc45..19dd71d4e349f228649f868f52b9a4e22efdc1ad 100644 (file)
@@ -374,7 +374,7 @@ rte_pmd_failsafe_probe(struct rte_vdev_device *vdev)
                        }
                        if (!devargs_already_listed(&devargs)) {
                                ret = rte_dev_probe(devargs.name);
-                               if (ret != 0) {
+                               if (ret < 0) {
                                        ERROR("Failed to probe devargs %s",
                                              devargs.name);
                                        continue;
index 820a915f776455e2254555fb0cccea7f67d7a4bf..b9fc508673f2b3c72c2b7eefbd1a8b51abf82c4c 100644 (file)
@@ -48,7 +48,7 @@ fs_bus_init(struct rte_eth_dev *dev)
                        ret = rte_eal_hotplug_add(da->bus->name,
                                                  da->name,
                                                  da->args);
-                       if (ret) {
+                       if (ret < 0) {
                                ERROR("sub_device %d probe failed %s%s%s", i,
                                      rte_errno ? "(" : "",
                                      rte_errno ? strerror(rte_errno) : "",
@@ -147,7 +147,7 @@ fs_bus_uninit(struct rte_eth_dev *dev)
 
        FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
                sdev_ret = rte_dev_remove(sdev->dev);
-               if (sdev_ret) {
+               if (sdev_ret < 0) {
                        ERROR("Failed to remove requested device %s (err: %d)",
                              sdev->dev->name, sdev_ret);
                        continue;
index 4746fad365171f7a017b6cec2380c2f57116d5e1..504c76edb0ffedff94fba26454b1246af21cf862 100644 (file)
@@ -284,7 +284,7 @@ fs_dev_remove(struct sub_device *sdev)
                /* fallthrough */
        case DEV_PROBED:
                ret = rte_dev_remove(sdev->dev);
-               if (ret) {
+               if (ret < 0) {
                        ERROR("Bus detach failed for sub_device %u",
                              SUB_ID(sdev));
                } else {
index edab63e3a5d3909192eadda442b89fcc997592e5..1fcf90d7bc02e0f7074021e293e939fb4986f6ef 100644 (file)
@@ -633,7 +633,7 @@ vdev_netvsc_netvsc_probe(const struct if_nameindex *iface,
                ctx->devname, ctx->devargs);
        vdev_netvsc_foreach_iface(vdev_netvsc_device_probe, 0, ctx);
        ret = rte_eal_hotplug_add("vdev", ctx->devname, ctx->devargs);
-       if (ret)
+       if (ret < 0)
                goto error;
        LIST_INSERT_HEAD(&vdev_netvsc_ctx_list, ctx, entry);
        ++vdev_netvsc_ctx_count;
index 86f801da7ddb4b3651c2be536946896d25c60cd3..9e4f09d83e2e360e3ba0af622e040700cde85cdd 100644 (file)
@@ -172,6 +172,9 @@ local_dev_probe(const char *devargs, struct rte_device **new_dev)
         */
 
        ret = dev->bus->plug(dev);
+       if (ret > 0)
+               ret = -ENOTSUP;
+
        if (ret && !rte_dev_is_probed(dev)) { /* if hasn't ever succeeded */
                RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
                        dev->name);
@@ -319,7 +322,7 @@ local_dev_remove(struct rte_device *dev)
        if (ret) {
                RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n",
                        dev->name);
-               return ret;
+               return (ret < 0) ? ret : -ENOENT;
        }
 
        return 0;