Skip to contentSkip to conversation

ARM: hisi: Fix refcount leak in hi3xxx_smp_prepare_cpus

PATCH In review Miaoqian Lin 2 participants 3 messages May 12, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: hisi: Fix refcount leak in hi3xxx_smp_prepare_cpus

of_find_compatible_node() returns a node pointer with refcount incremented, we should use of_node_put() on it when done. Add missing of_node_put() to avoid refcount leak.

Fixes a9434e96d9f0 ("ARM: hi3xxx: add smp support")
---
 arch/arm/mach-hisi/platsmp.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-hisi/platsmp.c +3 -0
index a56cc64deeb8..15e63b72df3a 100644
@@ -68,13 +68,16 @@ static void __init hi3xxx_smp_prepare_cpus(unsigned int max_cpus)
 		ctrl_base = of_iomap(np, 0);
 		if (!ctrl_base) {
 			pr_err("failed to map address\n");
+			of_node_put(np);
 			return;
 		}
 		if (of_property_read_u32(np, "smp-offset", &offset) < 0) {
 			pr_err("failed to find smp-offset property\n");
+			of_node_put(np);
 			return;
 		}
 		ctrl_base += offset;
+		of_node_put(np);
 	}
 }
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Hi Miaoqian,

Quoted 32 lines · Miaoqian Lin

of_find_compatible_node() returns a node pointer with refcount incremented, we should use of_node_put() on it when done. Add missing of_node_put() to avoid refcount leak.

Fixes a9434e96d9f0 ("ARM: hi3xxx: add smp support")
---
 arch/arm/mach-hisi/platsmp.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-hisi/platsmp.c +3 -0
index a56cc64deeb8..15e63b72df3a 100644
@@ -68,13 +68,16 @@ static void __init hi3xxx_smp_prepare_cpus(unsigned int max_cpus)
 		ctrl_base = of_iomap(np, 0);
 		if (!ctrl_base) {
 			pr_err("failed to map address\n");
+			of_node_put(np);
 			return;
 		}
 		if (of_property_read_u32(np, "smp-offset", &offset) < 0) {
 			pr_err("failed to find smp-offset property\n");
+			of_node_put(np);
 			return;
 		}
 		ctrl_base += offset;
+		of_node_put(np);
 	}
 }
 
maintainer
#2 lore raw
In reply to Miaoqian Lin

Hi Miaoqian,

Quoted 22 lines · Miaoqian Lin

of_find_compatible_node() returns a node pointer with refcount incremented, we should use of_node_put() on it when done. Add missing of_node_put() to avoid refcount leak.

Fixes a9434e96d9f0 ("ARM: hi3xxx: add smp support")
---
 arch/arm/mach-hisi/platsmp.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-hisi/platsmp.c +1 -0
index a56cc64deeb8..15e63b72df3a 100644
@@ -68,13 +68,16 @@ static void __init hi3xxx_smp_prepare_cpus(unsigned int max_cpus)
 		ctrl_base = of_iomap(np, 0);
 		if (!ctrl_base) {
 			pr_err("failed to map address\n");
+			of_node_put(np);
 			return;
 		}

arch/arm/mach-hisi/platsmp.c static void __init hi3xxx_smp_prepare_cpus(unsigned int max_cpus) · line 83

Quoted 10 lines
arch/arm/mach-hisi/platsmp.c +2 -0
 		if (of_property_read_u32(np, "smp-offset", &offset) < 0) {
 			pr_err("failed to find smp-offset property\n");
+			of_node_put(np);
 			return;
 		}
 		ctrl_base += offset;
+		of_node_put(np);
 	}
 }
 

Thanks!
But a similar patch[1] has been applied.

[1]: https://www.spinics.net/lists/arm-kernel/msg975425.html

Best Regards,
Wei