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/dpaa/dpaa_bus.c | 35 +++++++++++++---------------------- drivers/bus/fslmc/fslmc_bus.c | 27 +++++++++++++-------------- 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/drivers/bus/dpaa/dpaa_bus.c b/drivers/bus/dpaa/dpaa_bus.c index a439c22071..3915e0a8b7 100644 --- a/drivers/bus/dpaa/dpaa_bus.c +++ b/drivers/bus/dpaa/dpaa_bus.c @@ -215,16 +215,6 @@ dpaa_create_device_list(void) dev->device.numa_node = SOCKET_ID_ANY; - /* Allocate interrupt handle instance */ - dev->intr_handle = - rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE); - if (dev->intr_handle == NULL) { - DPAA_BUS_LOG(ERR, "Failed to allocate intr handle"); - ret = -ENOMEM; - free(dev); - goto cleanup; - } - cfg = &dpaa_netcfg->port_cfg[i]; fman_intf = cfg->fman_if; @@ -276,16 +266,6 @@ dpaa_create_device_list(void) goto cleanup; } - /* Allocate interrupt handle instance */ - dev->intr_handle = - rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE); - if (dev->intr_handle == NULL) { - DPAA_BUS_LOG(ERR, "Failed to allocate intr handle"); - ret = -ENOMEM; - free(dev); - goto cleanup; - } - dev->device_type = FSL_DPAA_CRYPTO; dev->id.dev_id = dpaa_bus.device_count + i; @@ -336,7 +316,6 @@ dpaa_create_device_list(void) cleanup: RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus) { rte_bus_remove_device(&rte_dpaa_bus, &dev->device); - rte_intr_instance_free(dev->intr_handle); free(dev); } @@ -788,9 +767,19 @@ dpaa_bus_probe_device(struct rte_driver *drv, struct rte_device *dev) struct rte_dpaa_driver *dpaa_drv = RTE_BUS_DRIVER(drv, *dpaa_drv); int ret; + /* Allocate interrupt handle instance */ + dpaa_dev->intr_handle = rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE); + if (dpaa_dev->intr_handle == NULL) { + DPAA_BUS_LOG(ERR, "Failed to allocate intr handle"); + return -ENOMEM; + } + ret = dpaa_drv->probe(dpaa_drv, dpaa_dev); - if (ret != 0) + if (ret != 0) { + rte_intr_instance_free(dpaa_dev->intr_handle); + dpaa_dev->intr_handle = NULL; DPAA_BUS_ERR("unable to probe: %s", dpaa_dev->name); + } return ret; } @@ -815,6 +804,8 @@ dpaa_bus_cleanup(void) rte_errno = errno; return -1; } + rte_intr_instance_free(dev->intr_handle); + dev->intr_handle = NULL; dev->device.driver = NULL; } dpaa_portal_finish((void *)DPAA_PER_LCORE_PORTAL); diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index 5870863189..fdc8bcb276 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -130,15 +130,6 @@ scan_one_fslmc_device(char *dev_name) dev->device.numa_node = SOCKET_ID_ANY; - /* Allocate interrupt instance */ - dev->intr_handle = - rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE); - if (dev->intr_handle == NULL) { - DPAA2_BUS_ERR("Failed to allocate intr handle"); - ret = -ENOMEM; - goto cleanup; - } - /* Parse the device name and ID */ t_ptr = strtok(dup_dev_name, "."); if (!t_ptr) { @@ -199,10 +190,7 @@ scan_one_fslmc_device(char *dev_name) return 0; cleanup: free(dup_dev_name); - if (dev) { - rte_intr_instance_free(dev->intr_handle); - free(dev); - } + free(dev); return ret; } @@ -405,7 +393,6 @@ rte_fslmc_scan(void) /* Remove all devices in the list */ RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { rte_bus_remove_device(&rte_fslmc_bus, &dev->device); - rte_intr_instance_free(dev->intr_handle); free(dev); } scan_fail: @@ -511,9 +498,19 @@ fslmc_bus_probe_device(struct rte_driver *driver, struct rte_device *rte_dev) return 0; } + /* Allocate interrupt instance */ + dev->intr_handle = + rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE); + if (dev->intr_handle == NULL) { + DPAA2_BUS_ERR("Failed to allocate intr handle"); + return -ENOMEM; + } + ret = drv->probe(drv, dev); if (ret != 0) { DPAA2_BUS_ERR("Unable to probe"); + rte_intr_instance_free(dev->intr_handle); + dev->intr_handle = NULL; } else { DPAA2_BUS_INFO("%s Plugged", dev->device.name); } @@ -529,6 +526,8 @@ fslmc_bus_unplug(struct rte_device *rte_dev) if (drv->remove != NULL) { drv->remove(dev); + rte_intr_instance_free(dev->intr_handle); + dev->intr_handle = NULL; dev->device.driver = NULL; DPAA2_BUS_INFO("%s Un-Plugged", dev->device.name); return 0; -- 2.53.0

