bcma: Put the OF node of a core when the core is released
PATCH 1/1 bcma: Put the OF node of a core when the core is released
bcma_of_find_child_device() returns the matching child from inside for_each_child_of_node(), so it hands a counted reference to its caller. bcma_of_fill_device() stores that node in core->dev.of_node, but bcma_release_core_dev() never puts it, so each core matched to a DT node leaks one device_node reference when it is released.
The node normally comes from the base device tree, and base-DT nodes are never freed: of_node_release() frees only detached OF_DYNAMIC nodes, i.e. overlay or changeset nodes. On a normal DT system the leak therefore has no memory effect.
Drop the reference in the release callback, where the lifetime of the core ends. The node is still assigned before device_add() and is not changed afterwards.
---
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.
An AI assistant traced the OF node reference and helped draft the fix.
The leak needs a DT-described bcma bus (a "brcm,bus-axi" SoC host such as BCM4708/BCM53xx, or a DT node under a bcma PCI host) and happens when a matched core is released (bus unbind, module unload).
drivers/bcma/main.c | 1 + 1 file changed, 1 insertion(+)
drivers/bcma/main.c +1 -0
@@ -123,6 +123,7 @@ static void bcma_release_core_dev(struct device *dev)iounmap (core->io_addr);if (core->io_wrap)iounmap (core->io_wrap); +of_node_put (dev->of_node);kfree (core); }
base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47