[EXTERNAL] [PATCH v3 10/11] bus/vmbus: store name in bus specific device
Long Li
longli at microsoft.com
Tue Jun 23 23:30:21 CEST 2026
> The device name is allocated with strdup() during scan and freed in several
> places. However, when this bus cleanup is converted to use the EAL generic
> helper, freeing the device object will require a custom helper to also free the
> device name (and for this, a cast will be needed).
>
> Instead, add an embedded name array to rte_vmbus_device structure (char
> name[RTE_DEV_NAME_MAX_LEN]) which is sufficient for all VMBUS device
> names (UUID format: 36 characters, or shorter legacy format).
>
> This simplifies the device freeing to a simple free() call.
>
> Signed-off-by: David Marchand <david.marchand at redhat.com>
> Acked-by: Bruce Richardson <bruce.richardson at intel.com>
Reviewed-by: Long Li <longli at microsoft.com>
> ---
> drivers/bus/vmbus/bus_vmbus_driver.h | 1 +
> drivers/bus/vmbus/linux/vmbus_bus.c | 10 +++-------
> 2 files changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/bus/vmbus/bus_vmbus_driver.h
> b/drivers/bus/vmbus/bus_vmbus_driver.h
> index 888d856141..706ff1fcf5 100644
> --- a/drivers/bus/vmbus/bus_vmbus_driver.h
> +++ b/drivers/bus/vmbus/bus_vmbus_driver.h
> @@ -38,6 +38,7 @@ enum hv_uio_map {
> */
> struct rte_vmbus_device {
> struct rte_device device; /**< Inherit core device */
> + char name[RTE_DEV_NAME_MAX_LEN]; /**< VMBUS device name
> */
> rte_uuid_t device_id; /**< VMBUS device id */
> rte_uuid_t class_id; /**< VMBUS device type */
> uint32_t relid; /**< id for primary */
> diff --git a/drivers/bus/vmbus/linux/vmbus_bus.c
> b/drivers/bus/vmbus/linux/vmbus_bus.c
> index 77d904ad6d..779ea50b92 100644
> --- a/drivers/bus/vmbus/linux/vmbus_bus.c
> +++ b/drivers/bus/vmbus/linux/vmbus_bus.c
> @@ -280,15 +280,14 @@ vmbus_scan_one(const char *name)
> char filename[PATH_MAX];
> char dirname[PATH_MAX];
> unsigned long tmp;
> - char *dev_name;
>
> dev = calloc(1, sizeof(*dev));
> if (dev == NULL)
> return -1;
>
> - dev->device.name = dev_name = strdup(name);
> - if (!dev->device.name)
> + if (rte_strscpy(dev->name, name, sizeof(dev->name)) < 0)
> goto error;
> + dev->device.name = dev->name;
>
> /* sysfs base directory
> * /sys/bus/vmbus/devices/7a08391f-f5a0-4ac0-9802-d13fd964f8df
> @@ -305,7 +304,6 @@ vmbus_scan_one(const char *name)
>
> /* skip non-network devices */
> if (rte_uuid_compare(dev->class_id, vmbus_nic_uuid) != 0) {
> - free(dev_name);
> free(dev);
> return 0;
> }
> @@ -330,7 +328,7 @@ vmbus_scan_one(const char *name)
> dev->monitor_id = UINT8_MAX;
> }
>
> - dev->device.devargs = rte_bus_find_devargs(&rte_vmbus_bus,
> dev_name);
> + dev->device.devargs = rte_bus_find_devargs(&rte_vmbus_bus, dev-
> >name);
>
> dev->device.numa_node = SOCKET_ID_ANY;
> if (vmbus_use_numa(dev)) {
> @@ -360,7 +358,6 @@ vmbus_scan_one(const char *name)
> } else { /* already registered */
> VMBUS_LOG(NOTICE,
> "%s already registered", name);
> - free(dev_name);
> free(dev);
> }
> return 0;
> @@ -371,7 +368,6 @@ vmbus_scan_one(const char *name)
> error:
> VMBUS_LOG(DEBUG, "failed");
>
> - free(dev_name);
> free(dev);
> return -1;
> }
> --
> 2.54.0
More information about the dev
mailing list