Skip to contentSkip to conversation

csky: fix refcount leak in setup_smp()

PATCH In review Yangtao Li 2 participants 2 messages Dec 27, 2018 C-sky architecture

lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH 1/1 csky: fix refcount leak in setup_smp()

The of_find_node_by_type() returns a node pointer with refcount incremented, but there is the lack of use of the of_node_put() when done. Add the missing of_node_put() to release the refcount.

---
 arch/csky/kernel/smp.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
arch/csky/kernel/smp.c +8 -2
index 36ebaf9834e1..adec56df613b 100644
@@ -139,11 +139,17 @@ void __init setup_smp(void)
 	int cpu;
 
 	while ((node = of_find_node_by_type(node, "cpu"))) {
-		if (!of_device_is_available(node))
+		if (!of_device_is_available(node)) {
+			of_node_put(node);
 			continue;
+		}
 
-		if (of_property_read_u32(node, "reg", &cpu))
+		if (of_property_read_u32(node, "reg", &cpu)) {
+			of_node_put(node);
 			continue;
+		}
+
+		of_node_put(node);
 
 		if (cpu >= NR_CPUS)
 			continue;
Signature · 1 line
2.17.0
maintainer
#1 lore raw

Hi Li,

Quoted 20 lines · Yangtao Li

The of_find_node_by_type() returns a node pointer with refcount incremented, but there is the lack of use of the of_node_put() when done. Add the missing of_node_put() to release the refcount.

---
 arch/csky/kernel/smp.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
arch/csky/kernel/smp.c +2 -1
index 36ebaf9834e1..adec56df613b 100644
@@ -139,11 +139,17 @@ void __init setup_smp(void)
 	int cpu;
 
 	while ((node = of_find_node_by_type(node, "cpu"))) {
-		if (!of_device_is_available(node))
+		if (!of_device_is_available(node)) {
+			of_node_put(node);

arch/csky/kernel/smp.c void __init setup_smp(void) · line 152

Quoted 10 lines
arch/csky/kernel/smp.c +6 -1
 			continue;
+		}
 
-		if (of_property_read_u32(node, "reg", &cpu))
+		if (of_property_read_u32(node, "reg", &cpu)) {
+			of_node_put(node);
 			continue;
+		}
+
+		of_node_put(node);

If success, of_node_put ?

arch/csky/kernel/smp.c void __init setup_smp(void) · line 154

Quoted 2 lines
arch/csky/kernel/smp.c +0 -0
 		if (cpu >= NR_CPUS)

Here need a of_node_put()?

arch/csky/kernel/smp.c void __init setup_smp(void) · line 154

Quoted 1 line
arch/csky/kernel/smp.c +0 -0
 			continue;

Can you use for_each_of_cpu_node() for the patch?

Thx
Guo Ren