Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ARM: hisi: fix device_node reference leak in hip04_smp_init
@ 2026-07-17  3:22 Wang Yan
  0 siblings, 0 replies; only message in thread
From: Wang Yan @ 2026-07-17  3:22 UTC (permalink / raw)
  To: xuwei5, linux
  Cc: haojian.zhuang, nico, linux-arm-kernel, linux-kernel, Wang Yan

The function hip04_smp_init() uses of_find_compatible_node() to
acquire three device_node pointers (np, np_sctl, np_fab), but
none of them are released on the success path or on error paths.
This results in reference count leaks for the corresponding
device tree nodes.

Fix this by:
- Initializing the three pointers to NULL so that of_node_put(NULL)
  is safe if a node was never acquired but the error path is taken.
- Adding of_node_put() calls for each acquired node on both the
  success path and the common error path.

Fixes: 9cdc99919a95 ("ARM: hisi: enable MCPM implementation")
Signed-off-by: Wang Yan <wangyan01@kylinos.cn>
---
 arch/arm/mach-hisi/platmcpm.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-hisi/platmcpm.c b/arch/arm/mach-hisi/platmcpm.c
index 258586e31333..89c8271763c9 100644
--- a/arch/arm/mach-hisi/platmcpm.c
+++ b/arch/arm/mach-hisi/platmcpm.c
@@ -264,7 +264,7 @@ static bool __init hip04_cpu_table_init(void)
 
 static int __init hip04_smp_init(void)
 {
-	struct device_node *np, *np_sctl, *np_fab;
+	struct device_node *np = NULL, *np_sctl = NULL, *np_fab = NULL;
 	struct resource fab_res;
 	void __iomem *relocation;
 	int ret = -ENODEV;
@@ -331,6 +331,9 @@ static int __init hip04_smp_init(void)
 	iounmap(relocation);
 
 	smp_set_ops(&hip04_smp_ops);
+	of_node_put(np_fab);
+	of_node_put(np_sctl);
+	of_node_put(np);
 	return ret;
 err_table:
 	iounmap(fabric);
@@ -341,6 +344,9 @@ static int __init hip04_smp_init(void)
 err_reloc:
 	memblock_phys_free(hip04_boot_method[0], hip04_boot_method[1]);
 err:
+	of_node_put(np_fab);
+	of_node_put(np_sctl);
+	of_node_put(np);
 	return ret;
 }
 early_initcall(hip04_smp_init);
-- 
2.25.1



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

only message in thread, other threads:[~2026-07-17  3:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-17  3:22 [PATCH] ARM: hisi: fix device_node reference leak in hip04_smp_init Wang Yan

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