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]>
Acked-by: Bruce Richardson <[email protected]>
---
 drivers/bus/ifpga/ifpga_bus.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c
index 2c22329f65..af77d69ef6 100644
--- a/drivers/bus/ifpga/ifpga_bus.c
+++ b/drivers/bus/ifpga/ifpga_bus.c
@@ -144,14 +144,6 @@ ifpga_scan_one(struct rte_rawdev *rawdev,
        afu_dev->id.uuid.uuid_high = 0;
        afu_dev->id.port      = afu_pr_conf.afu_id.port;
 
-       /* Allocate interrupt instance */
-       afu_dev->intr_handle =
-               rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
-       if (afu_dev->intr_handle == NULL) {
-               IFPGA_BUS_ERR("Failed to allocate intr handle");
-               goto end;
-       }
-
        if (rawdev->dev_ops && rawdev->dev_ops->dev_info_get)
                rawdev->dev_ops->dev_info_get(rawdev, afu_dev, 
sizeof(*afu_dev));
 
@@ -177,10 +169,7 @@ ifpga_scan_one(struct rte_rawdev *rawdev,
 end:
        rte_kvargs_free(kvlist);
        free(path);
-       if (afu_dev) {
-               rte_intr_instance_free(afu_dev->intr_handle);
-               free(afu_dev);
-       }
+       free(afu_dev);
 
        return NULL;
 }
@@ -272,8 +261,22 @@ ifpga_probe_device(struct rte_driver *drv, struct 
rte_device *dev)
 {
        struct rte_afu_device *afu_dev = RTE_BUS_DEVICE(dev, *afu_dev);
        struct rte_afu_driver *afu_drv = RTE_BUS_DRIVER(drv, *afu_drv);
+       int ret;
+
+       afu_dev->intr_handle =
+               rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
+       if (afu_dev->intr_handle == NULL) {
+               IFPGA_BUS_ERR("Failed to allocate intr handle");
+               return -ENOMEM;
+       }
+
+       ret = afu_drv->probe(afu_dev);
+       if (ret != 0) {
+               rte_intr_instance_free(afu_dev->intr_handle);
+               afu_dev->intr_handle = NULL;
+       }
 
-       return afu_drv->probe(afu_dev);
+       return ret;
 }
 
 /*
-- 
2.54.0

Reply via email to