From: Yige Jiang <yigejiang86@gmail.com>
To: "Rafał Miłecki" <zajec5@gmail.com>
Cc: Yige Jiang <yigejiang86@gmail.com>,
linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH] bcma: Release the found cores when the bus scan fails
Date: Thu, 26 Nov 2026 21:31:36 +0800 [thread overview]
Message-ID: <rc-b1-20261110-vc-96-1d8d0afe258d@gmail.com> (raw)
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
reply other threads:[~2026-11-26 13:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=rc-b1-20261110-vc-96-1d8d0afe258d@gmail.com \
--to=yigejiang86@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=zajec5@gmail.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