]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
riscv: Prevent a bad reference count on CPU nodes
authorMiquel Sabaté Solà <mikisabate@gmail.com>
Fri, 13 Sep 2024 08:00:52 +0000 (10:00 +0200)
committerPalmer Dabbelt <palmer@rivosinc.com>
Fri, 25 Oct 2024 13:18:39 +0000 (06:18 -0700)
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à <mikisabate@gmail.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Fixes: 604f32ea6909 ("riscv: cacheinfo: initialize cacheinfo's level and type from ACPI PPTT")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20240913080053.36636-1-mikisabate@gmail.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/kernel/cacheinfo.c

index b320b1d9aa01eff8cb41d4971f7f6dc461cce341..2d40736fc37cec788448d25c4ec5bdce802e581a 100644 (file)
@@ -80,8 +80,7 @@ int populate_cache_leaves(unsigned int cpu)
 {
        struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
        struct cacheinfo *this_leaf = this_cpu_ci->info_list;
-       struct device_node *np = of_cpu_device_node_get(cpu);
-       struct device_node *prev = NULL;
+       struct device_node *np, *prev;
        int levels = 1, level = 1;
 
        if (!acpi_disabled) {
@@ -105,6 +104,10 @@ int populate_cache_leaves(unsigned int cpu)
                return 0;
        }
 
+       np = of_cpu_device_node_get(cpu);
+       if (!np)
+               return -ENOENT;
+
        if (of_property_read_bool(np, "cache-size"))
                ci_leaf_init(this_leaf++, CACHE_TYPE_UNIFIED, level);
        if (of_property_read_bool(np, "i-cache-size"))