[v2] bus: fix leak for devices without driver

Message ID 20230209132207.1994066-1-vfialko@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [v2] 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/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-testing fail Testing issues
ci/iol-x86_64-unit-testing fail Testing issues
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Volodymyr Fialko Feb. 9, 2023, 1:22 p.m. UTC
  During the bus scan, memory for device configuration is allocated.
Currently, if a driver wasn't attached to the device during initialization,
memory for that device will not be released at bus cleanup.
This patch address this issue and releases the memory for all allocated
devices.

Fixes: 1cab1a40ea9b ("bus: cleanup devices on shutdown")
Cc: stable@dpdk.org

Signed-off-by: Volodymyr Fialko <vfialko@marvell.com>
---
V2:
- Updated commit message.

 drivers/bus/pci/pci_common.c | 3 ++-
 drivers/bus/vdev/vdev.c      | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)
  

Comments

Kevin Laatz Feb. 10, 2023, 9:28 a.m. UTC | #1
On 09/02/2023 13:22, Volodymyr Fialko wrote:
> During the bus scan, memory for device configuration is allocated.
> Currently, if a driver wasn't attached to the device during initialization,
> memory for that device will not be released at bus cleanup.
> This patch address this issue and releases the memory for all allocated
> devices.
>
> Fixes: 1cab1a40ea9b ("bus: cleanup devices on shutdown")
> Cc: stable@dpdk.org
>
> Signed-off-by: Volodymyr Fialko <vfialko@marvell.com>
> ---
> V2:
> - Updated commit message.
>
>   drivers/bus/pci/pci_common.c | 3 ++-
>   drivers/bus/vdev/vdev.c      | 5 +++--
>   2 files changed, 5 insertions(+), 3 deletions(-)
>
Acked-by: Kevin Laatz <kevin.laatz@intel.com>
  
David Marchand Feb. 10, 2023, 11:55 a.m. UTC | #2
On Fri, Feb 10, 2023 at 10:29 AM Kevin Laatz <kevin.laatz@intel.com> wrote:
>
> On 09/02/2023 13:22, Volodymyr Fialko wrote:
> > During the bus scan, memory for device configuration is allocated.
> > Currently, if a driver wasn't attached to the device during initialization,
> > memory for that device will not be released at bus cleanup.
> > This patch address this issue and releases the memory for all allocated
> > devices.
> >
> > Fixes: 1cab1a40ea9b ("bus: cleanup devices on shutdown")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Volodymyr Fialko <vfialko@marvell.com>
> Acked-by: Kevin Laatz <kevin.laatz@intel.com>

Applied, thanks.
  

Patch

diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index e0e15fd624..3b4196a43b 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -450,7 +450,7 @@  pci_cleanup(void)
 		int ret = 0;
 
 		if (drv == NULL || drv->remove == NULL)
-			continue;
+			goto free;
 
 		ret = drv->remove(dev);
 		if (ret < 0) {
@@ -460,6 +460,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);
 	}