mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] bcma: Release the found cores when the bus scan fails
@ 2026-11-26 13:31 Yige Jiang
  0 siblings, 0 replies; only message in thread
From: Yige Jiang @ 2026-11-26 13:31 UTC (permalink / raw)
  To: Rafał Miłecki; +Cc: Yige Jiang, linux-wireless, linux-kernel, stable

bcma_bus_scan() initializes each core it finds with bcma_prepare_core()
and links it on bus->cores. If a later EROM entry is malformed, or an
allocation or ioremap() fails, the scan returns an error with those
cores still linked, and neither host cleans them up:
bcma_host_pci_probe() jumps past bcma_unregister_cores() and frees the
bus, and bcma_host_soc_probe() only unmaps its MMIO window.

Each failed probe therefore leaks the device reference of every core
found so far, and with it the core, its name and, on SoC hosts, its
ioremap() mappings. The Sashiko AI review reported this as a
pre-existing issue in October 2026; an unmerged patch by Haotian Zhang
from August 2026 would have covered the SoC path as a side effect.

Release the cores in bcma_bus_scan() when it fails, with put_device()
as bcma_unregister_cores() does for cores that were never registered,
and reset bus->nr_cores so the bus is not treated as already scanned.
put_device() is the right release only since commit b63aed3ff195
("bcma: Fix memory leak for internally-handled cores"), which made
bcma_prepare_core() call device_initialize().

Fixes: 8369ae33b705 ("bcma: add Broadcom specific AMBA bus driver")
Cc: stable@vger.kernel.org # 5.15.x
Link: https://patchwork.kernel.org/project/linux-wireless/patch/20260813100836.2913-1-vulab@iscas.ac.cn/
Link: https://sashiko.dev/#/patchset/87897
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
Based on linux-next next-20261109 (630059a5a632).
Compile-tested: arm64, aarch64-linux-gnu-gcc 14.2.0, W=1, COMPILE_TEST=y, BCMA=m, BCMA_HOST_PCI=y, BCMA_HOST_SOC=y, OF_DYNAMIC=y; drivers/bcma/{main,scan}.o built before and after, no new warnings.
No hardware or runtime test was performed.

Needs bcma_bus_scan() to fail after at least one core was found: a malformed EROM entry, or an allocation/ioremap() failure.

 drivers/bcma/scan.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/bcma/scan.c b/drivers/bcma/scan.c
index 84742408a59c..6aea15f54b30 100644
--- a/drivers/bcma/scan.c
+++ b/drivers/bcma/scan.c
@@ -520,5 +520,16 @@ int bcma_bus_scan(struct bcma_bus *bus)
 	if (bus->hosttype == BCMA_HOSTTYPE_SOC)
 		iounmap(eromptr);
 
+	if (err) {
+		struct bcma_device *core, *tmp;
+
+		/* Release the cores found before the failure */
+		list_for_each_entry_safe(core, tmp, &bus->cores, list) {
+			list_del(&core->list);
+			put_device(&core->dev);
+		}
+		bus->nr_cores = 0;
+	}
+
 	return err;
 }

base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-26 13:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 13:31 [PATCH] bcma: Release the found cores when the bus scan fails Yige Jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®