DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@redhat.com>
To: hemant.agrawal@nxp.com, dev@dpdk.org
Cc: Sachin Saxena <sachin.saxena@nxp.com>
Subject: [PATCH 06/16] bus/fslmc: fix memory leaks in scan
Date: Wed, 14 Oct 2026 19:39:49 +0200	[thread overview]
Message-ID: <20261014174001.1830726-7-david.marchand@redhat.com> (raw)
In-Reply-To: <20261014174001.1830726-1-david.marchand@redhat.com>

During the scan phase (more precisely, during device filtering),
device pointers were leaked.

Add a simple helper so a device pointer is fully freed.

As a consequence of the filtering during scan, all blocklisted devices
are freed from the bus list during scan: there is no need for
reevaluating if a device is blocklisted during cleanup.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
Changes since RFC v1:
- fixed interrupt handle leak by adding fslmc_free_device helper
  sooner in the series,

---
 drivers/bus/fslmc/fslmc_bus.c  | 23 ++++++++++++++++++-----
 drivers/bus/fslmc/fslmc_vfio.c | 33 +++++++++------------------------
 drivers/bus/fslmc/private.h    |  2 ++
 3 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index 632142d128..38dd8afe34 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -85,6 +85,22 @@ insert_in_device_list(struct rte_dpaa2_device *newdev)
 		rte_bus_add_device(&rte_fslmc_bus, &newdev->device);
 }
 
+static void
+fslmc_free_device(struct rte_device *rte_dev)
+{
+	struct rte_dpaa2_device *dev = RTE_BUS_DEVICE(rte_dev, *dev);
+
+	rte_intr_instance_free(dev->intr_handle);
+	free(dev);
+}
+
+void
+fslmc_bus_remove_device(struct rte_dpaa2_device *dev)
+{
+	rte_bus_remove_device(&rte_fslmc_bus, &dev->device);
+	fslmc_free_device(&dev->device);
+}
+
 static void
 dump_device_list(void)
 {
@@ -369,11 +385,8 @@ rte_fslmc_scan(void)
 	closedir(dir);
 
 	/* Remove all devices in the list */
-	RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) {
-		rte_bus_remove_device(&rte_fslmc_bus, &dev->device);
-		rte_intr_instance_free(dev->intr_handle);
-		free(dev);
-	}
+	RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus)
+		fslmc_bus_remove_device(dev);
 scan_fail:
 	DPAA2_BUS_DEBUG("FSLMC Bus Not Available. Skipping (%d)", ret);
 	/* Irrespective of failure, scan only return success */
diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c
index c8b5518956..2a3d022d2e 100644
--- a/drivers/bus/fslmc/fslmc_vfio.c
+++ b/drivers/bus/fslmc/fslmc_vfio.c
@@ -1568,13 +1568,6 @@ fslmc_vfio_close_group(void)
 	}
 
 	RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) {
-		if (dev->device.devargs &&
-		    dev->device.devargs->policy == RTE_DEV_BLOCKED) {
-			DPAA2_BUS_LOG(DEBUG, "%s Blacklisted, skipping",
-				      dev->device.name);
-			rte_bus_remove_device(&rte_fslmc_bus, &dev->device);
-				continue;
-		}
 		switch (dev->dev_type) {
 		case DPAA2_ETH:
 		case DPAA2_CRYPTO:
@@ -1636,8 +1629,7 @@ fslmc_vfio_process_group(void)
 			    dev->device.devargs->policy == RTE_DEV_BLOCKED) {
 				DPAA2_BUS_LOG(DEBUG, "%s Blocked, skipping",
 					      dev->device.name);
-				rte_bus_remove_device(&rte_fslmc_bus,
-						&dev->device);
+				fslmc_bus_remove_device(dev);
 				continue;
 			}
 
@@ -1645,8 +1637,7 @@ fslmc_vfio_process_group(void)
 			    !is_dpmcp_in_blocklist) {
 				if (dpmcp_count == 1 ||
 				    current_device != dpmcp_count) {
-					rte_bus_remove_device(&rte_fslmc_bus,
-						     &dev->device);
+					fslmc_bus_remove_device(dev);
 					continue;
 				}
 			}
@@ -1660,9 +1651,7 @@ fslmc_vfio_process_group(void)
 				found_mportal = 1;
 			}
 
-			rte_bus_remove_device(&rte_fslmc_bus, &dev->device);
-			free(dev);
-			dev = NULL;
+			fslmc_bus_remove_device(dev);
 			/* Ideally there is only a single dpmcp, but in case
 			 * multiple exists, looping on remaining devices.
 			 */
@@ -1686,7 +1675,7 @@ fslmc_vfio_process_group(void)
 				DPAA2_BUS_ERR("Unable to process dprc");
 				return ret;
 			}
-			rte_bus_remove_device(&rte_fslmc_bus, &dev->device);
+			fslmc_bus_remove_device(dev);
 		}
 	}
 
@@ -1698,7 +1687,7 @@ fslmc_vfio_process_group(void)
 		    dev->device.devargs->policy == RTE_DEV_BLOCKED) {
 			DPAA2_BUS_LOG(DEBUG, "%s Blocked, skipping",
 				      dev->device.name);
-			rte_bus_remove_device(&rte_fslmc_bus, &dev->device);
+			fslmc_bus_remove_device(dev);
 			continue;
 		}
 		if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
@@ -1706,7 +1695,7 @@ fslmc_vfio_process_group(void)
 		    dev->dev_type != DPAA2_CRYPTO &&
 		    dev->dev_type != DPAA2_QDMA &&
 		    dev->dev_type != DPAA2_IO) {
-			rte_bus_remove_device(&rte_fslmc_bus, &dev->device);
+			fslmc_bus_remove_device(dev);
 			continue;
 		}
 		switch (dev->dev_type) {
@@ -1748,14 +1737,12 @@ fslmc_vfio_process_group(void)
 			if (!is_dpio_in_blocklist && dpio_count > 1) {
 				if (rte_eal_process_type() == RTE_PROC_SECONDARY
 				    && current_device != dpio_count) {
-					rte_bus_remove_device(&rte_fslmc_bus,
-						     &dev->device);
+					fslmc_bus_remove_device(dev);
 					break;
 				}
 				if (rte_eal_process_type() == RTE_PROC_PRIMARY
 				    && current_device == dpio_count) {
-					rte_bus_remove_device(&rte_fslmc_bus,
-						     &dev->device);
+					fslmc_bus_remove_device(dev);
 					break;
 				}
 			}
@@ -1773,9 +1760,7 @@ fslmc_vfio_process_group(void)
 			/* Unknown - ignore */
 			DPAA2_BUS_DEBUG("Found unknown device (%s)",
 					dev->device.name);
-			rte_bus_remove_device(&rte_fslmc_bus, &dev->device);
-			free(dev);
-			dev = NULL;
+			fslmc_bus_remove_device(dev);
 		}
 	}
 
diff --git a/drivers/bus/fslmc/private.h b/drivers/bus/fslmc/private.h
index 20a454c3fc..825a364f1b 100644
--- a/drivers/bus/fslmc/private.h
+++ b/drivers/bus/fslmc/private.h
@@ -11,4 +11,6 @@
 
 extern struct rte_bus rte_fslmc_bus;
 
+void fslmc_bus_remove_device(struct rte_dpaa2_device *dev);
+
 #endif /* BUS_FSLMC_PRIVATE_H */
-- 
2.54.0


  parent reply	other threads:[~2026-10-14 17:40 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23 13:53 [RFC 00/11] Device unplug and bus cleanup refactoring for NXP David Marchand
2026-07-23 13:53 ` [RFC 01/11] drivers/bus: cleanup device freeing in NXP bus scan David Marchand
2026-07-23 13:53 ` [RFC 02/11] bus/dpaa: allocate interrupt during probing David Marchand
2026-07-23 13:53 ` [RFC 03/11] bus/dpaa: support unplug and use generic cleanup David Marchand
2026-07-23 13:53 ` [RFC 04/11] bus/fslmc: fix memory leaks in scan David Marchand
2026-07-23 13:53 ` [RFC 05/11] bus/fslmc: fix per type device count David Marchand
2026-07-23 13:53 ` [RFC 06/11] bus/fslmc: simplify device parsing in scan David Marchand
2026-07-23 13:53 ` [RFC 07/11] bus/fslmc: refactor device filtering for multiprocess David Marchand
2026-07-23 13:53 ` [RFC 08/11] bus/fslmc: move unplug for some device out of VFIO David Marchand
2026-07-23 13:53 ` [RFC 09/11] bus/fslmc: call VFIO setup for some device from bus layer David Marchand
2026-07-23 13:53 ` [RFC 10/11] bus/fslmc: allocate interrupt during probing David Marchand
2026-07-23 13:53 ` [RFC 11/11] bus/fslmc: use generic cleanup David Marchand
2026-07-23 14:11 ` [RFC 00/11] Device unplug and bus cleanup refactoring for NXP Hemant Agrawal
2026-09-03 13:30   ` David Marchand
2026-09-08 14:20     ` Hemant Agrawal
2026-09-10 11:54       ` David Marchand
2026-08-11 20:09 ` Stephen Hemminger
2026-09-17  7:49 ` [RFC v2 00/16] " David Marchand
2026-09-17  7:49   ` [RFC v2 01/16] drivers/bus: cleanup device freeing in NXP bus scan David Marchand
2026-09-17  7:49   ` [RFC v2 02/16] drivers/bus: fix FD leak during scan in NXP drivers David Marchand
2026-09-17  7:49   ` [RFC v2 03/16] bus/dpaa: allocate interrupt during probing David Marchand
2026-09-17  7:49   ` [RFC v2 04/16] bus/dpaa: support unplug and use generic cleanup David Marchand
2026-09-17  7:49   ` [RFC v2 05/16] bus/fslmc: fix device name leak David Marchand
2026-09-17  7:49   ` [RFC v2 06/16] bus/fslmc: fix memory leaks in scan David Marchand
2026-09-17  7:49   ` [RFC v2 07/16] bus/fslmc: fix per type device count David Marchand
2026-09-17  7:49   ` [RFC v2 08/16] bus/fslmc: fix some VFIO device FD and memory leaks David Marchand
2026-09-17  7:49   ` [RFC v2 09/16] bus/fslmc: fix interrupt leak in DPIO cleanup David Marchand
2026-09-17  7:49   ` [RFC v2 10/16] bus/fslmc: simplify device parsing in scan David Marchand
2026-09-17  7:49   ` [RFC v2 11/16] bus/fslmc: release resources on scan failure David Marchand
2026-09-17  7:49   ` [RFC v2 12/16] bus/fslmc: refactor device filtering for multiprocess David Marchand
2026-09-17  7:49   ` [RFC v2 13/16] bus/fslmc: move unplug for some device out of VFIO David Marchand
2026-09-17  7:49   ` [RFC v2 14/16] bus/fslmc: call VFIO setup for some device from bus layer David Marchand
2026-09-17  7:49   ` [RFC v2 15/16] bus/fslmc: allocate interrupt during probing David Marchand
2026-09-17  7:49   ` [RFC v2 16/16] bus/fslmc: use generic cleanup David Marchand
2026-09-24  6:46   ` [RFC v2 00/16] Device unplug and bus cleanup refactoring for NXP David Marchand
2026-09-24  6:53     ` Hemant Agrawal
2026-10-14 17:39 ` [PATCH " David Marchand
2026-10-14 17:39   ` [PATCH 01/16] drivers/bus: cleanup device freeing in NXP bus scan David Marchand
2026-10-14 17:39   ` [PATCH 02/16] drivers/bus: fix FD leak during scan in NXP drivers David Marchand
2026-10-14 17:39   ` [PATCH 03/16] bus/dpaa: allocate interrupt during probing David Marchand
2026-10-14 17:39   ` [PATCH 04/16] bus/dpaa: support unplug and use generic cleanup David Marchand
2026-10-14 17:39   ` [PATCH 05/16] bus/fslmc: fix device name leak David Marchand
2026-10-14 17:39   ` David Marchand [this message]
2026-10-14 17:39   ` [PATCH 07/16] bus/fslmc: fix per type device count David Marchand
2026-10-14 17:39   ` [PATCH 08/16] bus/fslmc: fix some VFIO device FD and memory leaks David Marchand
2026-10-14 17:39   ` [PATCH 09/16] bus/fslmc: fix interrupt leak in DPIO cleanup David Marchand
2026-10-14 17:39   ` [PATCH 10/16] bus/fslmc: simplify device parsing in scan David Marchand
2026-10-14 17:39   ` [PATCH 11/16] bus/fslmc: release resources on probe failure David Marchand
2026-10-14 17:39   ` [PATCH 12/16] bus/fslmc: refactor device filtering for multiprocess David Marchand
2026-10-14 17:39   ` [PATCH 13/16] bus/fslmc: move unplug for some device out of VFIO David Marchand
2026-10-14 17:39   ` [PATCH 14/16] bus/fslmc: call VFIO setup for some device from bus layer David Marchand
2026-10-14 17:39   ` [PATCH 15/16] bus/fslmc: allocate interrupt during probing David Marchand
2026-10-14 17:39   ` [PATCH 16/16] bus/fslmc: use generic cleanup David Marchand
2026-10-18 10:34   ` [PATCH 00/16] Device unplug and bus cleanup refactoring for NXP Hemant Agrawal
2026-10-26  9:41     ` Prashant Gupta
2026-10-26 18:10       ` David Marchand
2026-10-27 11:20         ` [EXT] " Prashant Gupta
2026-10-26 18:10 ` [PATCH v2 " David Marchand
2026-10-26 18:10   ` [PATCH v2 01/16] drivers/bus: cleanup device freeing in NXP bus scan David Marchand
2026-10-26 18:10   ` [PATCH v2 02/16] drivers/bus: fix FD leak during scan in NXP drivers David Marchand
2026-10-26 18:10   ` [PATCH v2 03/16] bus/dpaa: allocate interrupt during probing David Marchand
2026-10-26 18:10   ` [PATCH v2 04/16] bus/dpaa: support unplug and use generic cleanup David Marchand
2026-10-26 18:10   ` [PATCH v2 05/16] bus/fslmc: fix device name leak David Marchand
2026-10-26 18:10   ` [PATCH v2 06/16] bus/fslmc: fix memory leaks in scan David Marchand
2026-10-26 18:10   ` [PATCH v2 07/16] bus/fslmc: fix per type device count David Marchand
2026-10-26 18:10   ` [PATCH v2 08/16] bus/fslmc: fix some VFIO device FD and memory leaks David Marchand
2026-10-26 18:10   ` [PATCH v2 09/16] bus/fslmc: fix interrupt leak in DPIO cleanup David Marchand
2026-10-26 18:10   ` [PATCH v2 10/16] bus/fslmc: simplify device parsing in scan David Marchand
2026-10-26 18:10   ` [PATCH v2 11/16] bus/fslmc: release resources on probe failure David Marchand
2026-10-26 18:10   ` [PATCH v2 12/16] bus/fslmc: refactor device filtering for multiprocess David Marchand
2026-10-26 18:10   ` [PATCH v2 13/16] bus/fslmc: move unplug for some device out of VFIO David Marchand
2026-10-26 18:10   ` [PATCH v2 14/16] bus/fslmc: call VFIO setup for some device from bus layer David Marchand
2026-10-26 18:10   ` [PATCH v2 15/16] bus/fslmc: allocate interrupt during probing David Marchand
2026-10-26 18:10   ` [PATCH v2 16/16] bus/fslmc: use generic cleanup David Marchand
2026-10-27 12:36   ` [PATCH v2 00/16] Device unplug and bus cleanup refactoring for NXP Hemant Agrawal
2026-10-27 16:44     ` 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=20261014174001.1830726-7-david.marchand@redhat.com \
    --to=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=hemant.agrawal@nxp.com \
    --cc=sachin.saxena@nxp.com \
    /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