[PATCH] sh: sh2: Fix refcount leak bug in smp-j2

From: Liang He
Date: Fri Jun 17 2022 - 08:04:16 EST


In j2_prepare_cpus(), of_find_compatible_node() will return a
node pointer with refcount incremented. We should use of_node_put()
in fail path or when it is not used anymore.

Signed-off-by: Liang He <windhl@xxxxxxx>
---
arch/sh/kernel/cpu/sh2/smp-j2.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/sh/kernel/cpu/sh2/smp-j2.c b/arch/sh/kernel/cpu/sh2/smp-j2.c
index d0d5d81455ae..995fb5da6ff3 100644
--- a/arch/sh/kernel/cpu/sh2/smp-j2.c
+++ b/arch/sh/kernel/cpu/sh2/smp-j2.c
@@ -51,6 +51,7 @@ static void j2_prepare_cpus(unsigned int max_cpus)

j2_ipi_irq = irq_of_parse_and_map(np, 0);
j2_ipi_trigger = of_iomap(np, 0);
+ of_node_put(np);
if (!j2_ipi_irq || !j2_ipi_trigger)
goto out;

@@ -59,6 +60,7 @@ static void j2_prepare_cpus(unsigned int max_cpus)
goto out;

sh2_cpuid_addr = of_iomap(np, 0);
+ of_node_put(np);
if (!sh2_cpuid_addr)
goto out;

--
2.25.1