bus: fix leak for devices without driver

Message ID 20230107151230.2539470-1-vfialko@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series bus: fix leak for devices without driver |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Performance fail Performance Testing issues
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Volodymyr Fialko Jan. 7, 2023, 3:12 p.m. UTC
  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@marvell.com>
---
 drivers/bus/pci/pci_common.c | 3 ++-
 drivers/bus/vdev/vdev.c      | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)
  

Comments

David Marchand Feb. 7, 2023, 1:48 p.m. UTC | #1
On Sat, Jan 7, 2023 at 4:12 PM Volodymyr Fialko <vfialko@marvell.com> wrote:
>
> 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")

Worth copying stable.

>
> Signed-off-by: Volodymyr Fialko <vfialko@marvell.com>

At a quick glance, the fix lgtm.
Kevin, can you double check this fix thoroughly?

Thanks.
  
Kevin Laatz Feb. 8, 2023, 11:30 a.m. UTC | #2
Hi Volodymyr,

On 07/01/2023 15:12, Volodymyr Fialko wrote:
> 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@marvell.com>
> ---
>   drivers/bus/pci/pci_common.c | 3 ++-
>   drivers/bus/vdev/vdev.c      | 5 +++--
>   2 files changed, 5 insertions(+), 3 deletions(-)
>
This fix LGTM, but its tricky to reproduce so I have not been able to 
test this.

Could you add some more text to the commit message describing the issue 
and fix, please?

/Kevin
  

Patch

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);
 	}