bcma: Release the found cores when the bus scan fails
Subsystems (2)
PATCH 1/1 bcma: Release the found cores when the bus scan fails
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().
---
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(+)
drivers/bcma/scan.c +11 -0
@@ -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