Skip to content

Commit 3723316

Browse files
mssolapalmer-dabbelt
authored andcommitted
riscv: Prevent a bad reference count on CPU nodes
When populating cache leaves we previously fetched the CPU device node at the very beginning. But when ACPI is enabled we go through a specific branch which returns early and does not call 'of_node_put' for the node that was acquired. Since we are not using a CPU device node for the ACPI code anyways, we can simply move the initialization of it just passed the ACPI block, and we are guaranteed to have an 'of_node_put' call for the acquired node. This prevents a bad reference count of the CPU device node. Moreover, the previous function did not check for errors when acquiring the device node, so a return -ENOENT has been added for that case. Signed-off-by: Miquel Sabaté Solà <[email protected]> Reviewed-by: Sudeep Holla <[email protected]> Reviewed-by: Sunil V L <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Fixes: 604f32e ("riscv: cacheinfo: initialize cacheinfo's level and type from ACPI PPTT") Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent d41373a commit 3723316

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

arch/riscv/kernel/cacheinfo.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ int populate_cache_leaves(unsigned int cpu)
8080
{
8181
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
8282
struct cacheinfo *this_leaf = this_cpu_ci->info_list;
83-
struct device_node *np = of_cpu_device_node_get(cpu);
84-
struct device_node *prev = NULL;
83+
struct device_node *np, *prev;
8584
int levels = 1, level = 1;
8685

8786
if (!acpi_disabled) {
@@ -105,6 +104,10 @@ int populate_cache_leaves(unsigned int cpu)
105104
return 0;
106105
}
107106

107+
np = of_cpu_device_node_get(cpu);
108+
if (!np)
109+
return -ENOENT;
110+
108111
if (of_property_read_bool(np, "cache-size"))
109112
ci_leaf_init(this_leaf++, CACHE_TYPE_UNIFIED, level);
110113
if (of_property_read_bool(np, "i-cache-size"))

0 commit comments

Comments
 (0)