Skip to contentSkip to conversation

arch: arm: mach-spear: Add missing of_node_put() in time.c

PATCH Superseded Liang He 2 participants 3 messages Jun 15, 2022 – Jun 16, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 arch: arm: mach-spear: Add missing of_node_put() in time.c

In spear_setup_of_timer(), of_find_matching_node() will return a node pointer with refcount incrementd. We should use of_node_put() in each fail path or when it is not used anymore.

---
 arch/arm/mach-spear/time.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mach-spear/time.c +5 -1
index d1fdb6066f7b..a1b6635b4ecb 100644
@@ -217,16 +217,20 @@ void __init spear_setup_of_timer(void)
 
 	irq = irq_of_parse_and_map(np, 0);
 	if (!irq) {
+		of_node_put(np);
 		pr_err("%s: No irq passed for timer via DT\n", __func__);
 		return;
 	}
 
 	gpt_base = of_iomap(np, 0);
 	if (!gpt_base) {
+		of_node_put(np);
 		pr_err("%s: of iomap failed\n", __func__);
 		return;
 	}
-
+	
+	of_node_put(np);
+	
 	gpt_clk = clk_get_sys("gpt0", NULL);
 	if (IS_ERR(gpt_clk)) {
 		pr_err("%s:couldn't get clk for gpt\n", __func__);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 25 lines · Liang He

In spear_setup_of_timer(), of_find_matching_node() will return a node pointer with refcount incrementd. We should use of_node_put() in each fail path or when it is not used anymore.

---
 arch/arm/mach-spear/time.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mach-spear/time.c +2 -0
index d1fdb6066f7b..a1b6635b4ecb 100644
@@ -217,16 +217,20 @@ void __init spear_setup_of_timer(void)
 
 	irq = irq_of_parse_and_map(np, 0);
 	if (!irq) {
+		of_node_put(np);
 		pr_err("%s: No irq passed for timer via DT\n", __func__);
 		return;
 	}
 
 	gpt_base = of_iomap(np, 0);
 	if (!gpt_base) {
+		of_node_put(np);

arch/arm/mach-spear/time.c void __init spear_setup_of_timer(void) · line 236

Quoted 10 lines
arch/arm/mach-spear/time.c +3 -1
 		pr_err("%s: of iomap failed\n", __func__);
 		return;
 	}
-
+	
+	of_node_put(np);
+	
 	gpt_clk = clk_get_sys("gpt0", NULL);
 	if (IS_ERR(gpt_clk)) {
 		pr_err("%s:couldn't get clk for gpt\n", __func__);

Since this routine already have error labels, for consistence it would be better to add another one "err_put_np" and use goto to that ?

Signature · 1 line
viresh
author
#2 lore raw
Quoted 23 lines · Viresh Kumar
Quoted 22 lines · Liang He

In spear_setup_of_timer(), of_find_matching_node() will return a node pointer with refcount incrementd. We should use of_node_put() in each fail path or when it is not used anymore.

---
 arch/arm/mach-spear/time.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mach-spear/time.c +1 -0
index d1fdb6066f7b..a1b6635b4ecb 100644
@@ -217,16 +217,20 @@ void __init spear_setup_of_timer(void)
 
 	irq = irq_of_parse_and_map(np, 0);
 	if (!irq) {
+		of_node_put(np);
 		pr_err("%s: No irq passed for timer via DT\n", __func__);
 		return;
 	}
 
Quoted 19 lines

arch/arm/mach-spear/time.c void __init spear_setup_of_timer(void) · line 236

Quoted 13 lines
arch/arm/mach-spear/time.c +4 -1
 	gpt_base = of_iomap(np, 0);
 	if (!gpt_base) {
+		of_node_put(np);
 		pr_err("%s: of iomap failed\n", __func__);
 		return;
 	}
-
+	
+	of_node_put(np);
+	
 	gpt_clk = clk_get_sys("gpt0", NULL);
 	if (IS_ERR(gpt_clk)) {
 		pr_err("%s:couldn't get clk for gpt\n", __func__);

Since this routine already have error labels, for consistence it would be better to add another one "err_put_np" and use goto to that ?

Signature · 1 line
viresh

Thanks for your reply. I will make a new patch for that.

Liang