net/virtio: fix incorrect cast of void *
[dpdk.git] / lib / librte_eal / common / eal_common_dev.c
index e10b9fd..dda8f58 100644 (file)
@@ -66,26 +66,26 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
 
 int rte_eal_dev_attach(const char *name, const char *devargs)
 {
-       int ret;
+       struct rte_bus *bus;
 
        if (name == NULL || devargs == NULL) {
                RTE_LOG(ERR, EAL, "Invalid device or arguments provided\n");
                return -EINVAL;
        }
 
-       ret = rte_eal_hotplug_add("pci", name, devargs);
-       if (ret && ret != -EINVAL)
-               return ret;
-
-       /*
-        * If we haven't found a bus device the user meant to "hotplug" a
-        * virtual device instead.
-        */
-       ret = rte_vdev_init(name, devargs);
-       if (ret)
-               RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
+       bus = rte_bus_find_by_device_name(name);
+       if (bus == NULL) {
+               RTE_LOG(ERR, EAL, "Unable to find a bus for the device '%s'\n",
                        name);
-       return ret;
+               return -EINVAL;
+       }
+       if (strcmp(bus->name, "pci") == 0 || strcmp(bus->name, "vdev") == 0)
+               return rte_eal_hotplug_add(bus->name, name, devargs);
+
+       RTE_LOG(ERR, EAL,
+               "Device attach is only supported for PCI and vdev devices.\n");
+
+       return -ENOTSUP;
 }
 
 int rte_eal_dev_detach(struct rte_device *dev)
@@ -123,16 +123,13 @@ full_dev_name(const char *bus, const char *dev, const char *args)
        char *name;
        size_t len;
 
-       len = strlen(bus) + 1 +
-             strlen(dev) + 1 +
-             strlen(args) + 1;
+       len = snprintf(NULL, 0, "%s:%s,%s", bus, dev, args) + 1;
        name = calloc(1, len);
        if (name == NULL) {
                RTE_LOG(ERR, EAL, "Could not allocate full device name\n");
                return NULL;
        }
-       snprintf(name, len, "%s:%s,%s", bus, dev,
-                args ? args : "");
+       snprintf(name, len, "%s:%s,%s", bus, dev, args);
        return name;
 }
 
@@ -197,7 +194,10 @@ int rte_eal_hotplug_add(const char *busname, const char *devname,
        return 0;
 
 err_devarg:
-       rte_eal_devargs_remove(busname, devname);
+       if (rte_eal_devargs_remove(busname, devname)) {
+               free(da->args);
+               free(da);
+       }
 err_name:
        free(name);
        return ret;