> Allocating the interrupt handle is a waste of memory if no device is probed
> later (like for example, if a allowlist is passed).
> Instead, allocate this handle at the time probe_device is called.
> 
> Signed-off-by: David Marchand <[email protected]>
> ---
>  drivers/bus/vmbus/linux/vmbus_bus.c |  6 ------
>  drivers/bus/vmbus/vmbus_common.c    | 18 +++++++++++++++++-
>  2 files changed, 17 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/bus/vmbus/linux/vmbus_bus.c
> b/drivers/bus/vmbus/linux/vmbus_bus.c
> index 0af10f6a69..77d904ad6d 100644
> --- a/drivers/bus/vmbus/linux/vmbus_bus.c
> +++ b/drivers/bus/vmbus/linux/vmbus_bus.c
> @@ -345,12 +345,6 @@ vmbus_scan_one(const char *name)
>               }
>       }
> 
> -     /* Allocate interrupt handle instance */
> -     dev->intr_handle =
> -             rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
> -     if (dev->intr_handle == NULL)
> -             goto error;
> -
>       /* device is valid, add in list (sorted) */
>       VMBUS_LOG(DEBUG, "Adding vmbus device %s", name);
> 
> diff --git a/drivers/bus/vmbus/vmbus_common.c
> b/drivers/bus/vmbus/vmbus_common.c
> index 74c1ddff69..b6ae82915f 100644
> --- a/drivers/bus/vmbus/vmbus_common.c
> +++ b/drivers/bus/vmbus/vmbus_common.c
> @@ -108,11 +108,27 @@ vmbus_probe_device(struct rte_driver *drv, struct
> rte_device *dev)
>       if (vmbus_dev->device.numa_node < 0 && rte_socket_count() > 1)
>               VMBUS_LOG(INFO, "Device %s is not NUMA-aware", guid);
> 
> +     /* Allocate interrupt handle instance */
> +     vmbus_dev->intr_handle =
> +             rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
> +     if (vmbus_dev->intr_handle == NULL) {
> +             ret = -ENOMEM;
> +             goto unmap;
> +     }
> +
>       /* call the driver probe() function */
>       VMBUS_LOG(INFO, "  probe driver: %s", vmbus_drv->driver.name);
>       ret = vmbus_drv->probe(vmbus_drv, vmbus_dev);
>       if (ret != 0)
> -             rte_vmbus_unmap_device(vmbus_dev);
> +             goto free_intr;
> +
> +     return 0;
> +
> +free_intr:
> +     rte_intr_instance_free(vmbus_dev->intr_handle);
> +     vmbus_dev->intr_handle = NULL;
> +unmap:
> +     rte_vmbus_unmap_device(vmbus_dev);
> 
>       return ret;
>  }
> --
> 2.53.0

rte_vmbus_map_device() needs intr_handle to already exist, so need to move 
rte_intr_instance_alloc to earlier before calling rte_vmbus_map_device(),
something like this:

diff --git a/drivers/bus/vmbus/vmbus_common.c b/drivers/bus/vmbus/vmbus_common.c
index 419eb9b895..f3bcb90e46 100644
--- a/drivers/bus/vmbus/vmbus_common.c
+++ b/drivers/bus/vmbus/vmbus_common.c
@@ -100,35 +100,33 @@ vmbus_probe_device(struct rte_driver *drv, struct 
rte_device *dev)
                return 1;
        }

+       /* Allocate interrupt handle instance */
+       vmbus_dev->intr_handle =
+               rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
+       if (vmbus_dev->intr_handle == NULL)
+               return -ENOMEM;
+
        /* map resources for device */
        ret = rte_vmbus_map_device(vmbus_dev);
        if (ret != 0)
-               return ret;
+               goto free_intr;

        if (vmbus_dev->device.numa_node < 0 && rte_socket_count() > 1)
                VMBUS_LOG(INFO, "Device %s is not NUMA-aware", guid);

-       /* Allocate interrupt handle instance */
-       vmbus_dev->intr_handle =
-               rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
-       if (vmbus_dev->intr_handle == NULL) {
-               ret = -ENOMEM;
-               goto unmap;
-       }
-
        /* call the driver probe() function */
        VMBUS_LOG(INFO, "  probe driver: %s", vmbus_drv->driver.name);
        ret = vmbus_drv->probe(vmbus_drv, vmbus_dev);
        if (ret != 0)
-               goto free_intr;
+               goto unmap;

        return 0;

+unmap:
+       rte_vmbus_unmap_device(vmbus_dev);
 free_intr:
        rte_intr_instance_free(vmbus_dev->intr_handle);
        vmbus_dev->intr_handle = NULL;
-unmap:
-       rte_vmbus_unmap_device(vmbus_dev);

        return ret;
 }

Reply via email to