public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] riscv: cacheinfo: Fix node reference leak in populate_cache_leaves
@ 2026-03-23 11:59 Zishun Yi
  2026-03-23 19:36 ` Markus Elfring
  0 siblings, 1 reply; 2+ messages in thread
From: Zishun Yi @ 2026-03-23 11:59 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou
  Cc: Alexandre Ghiti, Atish Patra, linux-riscv, linux-kernel,
	Zishun Yi, stable

Currently, the while loop drops the reference to prev in each iteration.
If the loop terminates early due to a break, the final of_node_put(np)
correctly drops the reference to the current node.

However, if the loop terminates naturally because np == NULL, calling
of_node_put(np) is a no-op. This leaves the last valid node stored in
prev without its reference dropped, resulting in a node reference leak.

Fix this by changing the final `of_node_put(np)` to `of_node_put(prev)`.

Fixes: 94f9bf118f1e ("RISC-V: Fix of_node_* refcount")
Cc: stable@vger.kernel.org
Signed-off-by: Zishun Yi <vulab@iscas.ac.cn>
---
I saw 37233169a6ea ("riscv: Prevent a bad reference count on CPU nodes")
added the stable tag and fixed a similar issue, so I included it here as
well.

 arch/riscv/kernel/cacheinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/cacheinfo.c b/arch/riscv/kernel/cacheinfo.c
index 26b085dbdd07..6c9a1ef2d45a 100644
--- a/arch/riscv/kernel/cacheinfo.c
+++ b/arch/riscv/kernel/cacheinfo.c
@@ -133,7 +133,7 @@ int populate_cache_leaves(unsigned int cpu)
 			ci_leaf_init(this_leaf++, CACHE_TYPE_DATA, level);
 		levels = level;
 	}
-	of_node_put(np);
+	of_node_put(prev);
 
 	return 0;
 }
-- 
2.51.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] riscv: cacheinfo: Fix node reference leak in populate_cache_leaves
  2026-03-23 11:59 [PATCH] riscv: cacheinfo: Fix node reference leak in populate_cache_leaves Zishun Yi
@ 2026-03-23 19:36 ` Markus Elfring
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2026-03-23 19:36 UTC (permalink / raw)
  To: vulab, linux-riscv, Albert Ou, Palmer Dabbelt, Paul Walmsley
  Cc: stable, LKML, kernel-janitors, Alexandre Ghiti, Atish Patra

…
> Fix this by changing the final `of_node_put(np)` to `of_node_put(prev)`.

How do you think about to use a wording approach like “Thus replace
the passed variable np by prev in an of_node_put() call at the end of
this function implementation”?


…
> Signed-off-by: Zishun Yi <vulab@iscas.ac.cn>

Can further clarifications become helpful also for the safe usage of
the Developer's Certificate of Origin?

Regards,
Markus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-23 19:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-23 11:59 [PATCH] riscv: cacheinfo: Fix node reference leak in populate_cache_leaves Zishun Yi
2026-03-23 19:36 ` Markus Elfring

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