[PATCH] bus: fix leak for devices without driver

Volodymyr Fialko vfialko at marvell.com
Sat Jan 7 16:12:30 CET 2023


For devices not assigned to any driver, we leak a pci device object since
it is never freed from the PCI bus device list, reported by ASAN.

Fixes: 1cab1a40ea9b ("bus: cleanup devices on shutdown")

Signed-off-by: Volodymyr Fialko <vfialko at marvell.com>
---
 drivers/bus/pci/pci_common.c | 3 ++-
 drivers/bus/vdev/vdev.c      | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index bc3a7f39fe..e32a9d517a 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -448,7 +448,7 @@ pci_cleanup(void)
 		int ret = 0;
 
 		if (drv == NULL || drv->remove == NULL)
-			continue;
+			goto free;
 
 		ret = drv->remove(dev);
 		if (ret < 0) {
@@ -458,6 +458,7 @@ pci_cleanup(void)
 		dev->driver = NULL;
 		dev->device.driver = NULL;
 
+free:
 		/* free interrupt handles */
 		rte_intr_instance_free(dev->intr_handle);
 		dev->intr_handle = NULL;
diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index 41bc07dde7..7974b27295 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -578,18 +578,19 @@ vdev_cleanup(void)
 		int ret = 0;
 
 		if (dev->device.driver == NULL)
-			continue;
+			goto free;
 
 		drv = container_of(dev->device.driver, const struct rte_vdev_driver, driver);
 
 		if (drv->remove == NULL)
-			continue;
+			goto free;
 
 		ret = drv->remove(dev);
 		if (ret < 0)
 			error = -1;
 
 		dev->device.driver = NULL;
+free:
 		free(dev);
 	}
 
-- 
2.34.1



More information about the dev mailing list