]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
riscv: cacheinfo: Fix node reference leak in populate_cache_leaves
authorZishun Yi <vulab@iscas.ac.cn>
Sun, 7 Jun 2026 02:17:58 +0000 (20:17 -0600)
committerPaul Walmsley <pjw@kernel.org>
Sun, 7 Jun 2026 05:48:15 +0000 (23:48 -0600)
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
Assisted-by: Gemini:gemini-3.1-pro
Signed-off-by: Zishun Yi <vulab@iscas.ac.cn>
Link: https://patch.msgid.link/20260509074040.1747800-1-vulab@iscas.ac.cn
Signed-off-by: Paul Walmsley <pjw@kernel.org>
arch/riscv/kernel/cacheinfo.c

index 26b085dbdd073fbcaf2d581f43e72e4923a001d6..6c9a1ef2d45af1e91ba681d3cb7efd331d026f62 100644 (file)
@@ -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;
 }