Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Wang Yan <wangyan01@kylinos.cn>
To: xuwei5@hisilicon.com, linux@armlinux.org.uk
Cc: haojian.zhuang@linaro.org, nico@fluxnic.net,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Wang Yan <wangyan01@kylinos.cn>
Subject: [PATCH] ARM: hisi: fix device_node reference leak in hip04_smp_init
Date: Fri, 17 Jul 2026 11:22:27 +0800	[thread overview]
Message-ID: <20260717032227.64214-1-wangyan01@kylinos.cn> (raw)

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



                 reply	other threads:[~2026-07-17  3:22 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=20260717032227.64214-1-wangyan01@kylinos.cn \
    --to=wangyan01@kylinos.cn \
    --cc=haojian.zhuang@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=nico@fluxnic.net \
    --cc=xuwei5@hisilicon.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