DPDK patches and discussions
 help / color / mirror / Atom feed
From: Volodymyr Fialko <vfialko@marvell.com>
To: dev@dpdk.org, "Bruce Richardson" <bruce.richardson@intel.com>,
	"Kevin Laatz" <kevin.laatz@intel.com>,
	"Morten Brørup" <mb@smartsharesystems.com>
Cc: <jerinj@marvell.com>, <david.marchand@redhat.com>,
	Volodymyr Fialko <vfialko@marvell.com>, <stable@dpdk.org>
Subject: [PATCH v2] bus: fix leak for devices without driver
Date: Thu, 9 Feb 2023 14:22:07 +0100	[thread overview]
Message-ID: <20230209132207.1994066-1-vfialko@marvell.com> (raw)
In-Reply-To: <20230107151230.2539470-1-vfialko@marvell.com>

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(-)

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


  parent reply	other threads:[~2023-02-09 13:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-07 15:12 [PATCH] " Volodymyr Fialko
2023-02-07 13:48 ` David Marchand
2023-02-08 11:30 ` Kevin Laatz
2023-02-09 13:22 ` Volodymyr Fialko [this message]
2023-02-10  9:28   ` [PATCH v2] " Kevin Laatz
2023-02-10 11:55     ` David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230209132207.1994066-1-vfialko@marvell.com \
    --to=vfialko@marvell.com \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=kevin.laatz@intel.com \
    --cc=mb@smartsharesystems.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).