Skip to contentSkip to conversation

powerpc/powermac/udbg_scc: Fix refcount leak bug in udbg_scc_init()

PATCH Applied Liang He 3 participants 3 messages Jul 16, 2022 – Sep 9, 2022

Subsystems (2)
lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 powerpc/powermac/udbg_scc: Fix refcount leak bug in udbg_scc_init()

During the iteration of for_each_child_of_node(), we need to call of_node_put() for the old references stored in to 'ch_def' and 'ch_a' as their refcounters have been increased in last iteration.

Fixes 51d3082fe6e5 ("[PATCH] powerpc: Unify udbg (#2)")
---
 arch/powerpc/platforms/powermac/udbg_scc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/powerpc/platforms/powermac/udbg_scc.c +6 -2
index 734df5a32f99..1b7c39e841ee 100644
@@ -81,10 +81,14 @@ void __init udbg_scc_init(int force_scc)
 	if (path != NULL)
 		stdout = of_find_node_by_path(path);
 	for_each_child_of_node(escc, ch) {
-		if (ch == stdout)
+		if (ch == stdout) {
+			of_node_put(ch_def);
 			ch_def = of_node_get(ch);
-		if (of_node_name_eq(ch, "ch-a"))
+		}
+		if (of_node_name_eq(ch, "ch-a")) {
+			of_node_put(ch_a);
 			ch_a = of_node_get(ch);
+		}
 	}
 	if (ch_def == NULL && !force_scc)
 		goto bail;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 3 lines · Liang He

During the iteration of for_each_child_of_node(), we need to call of_node_put() for the old references stored in to 'ch_def' and 'ch_a' as their refcounters have been increased in last iteration.

None of these matter since those nodes are never *ever* released and those machines don't use dynamic node allocation but ...

Quoted 28 lines
Fixes 51d3082fe6e5 ("[PATCH] powerpc: Unify udbg (#2)")
---
 arch/powerpc/platforms/powermac/udbg_scc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/powerpc/platforms/powermac/udbg_scc.c +6 -2
index 734df5a32f99..1b7c39e841ee 100644
@@ -81,10 +81,14 @@ void __init udbg_scc_init(int force_scc)
 	if (path != NULL)
 		stdout = of_find_node_by_path(path);
 	for_each_child_of_node(escc, ch) {
-		if (ch == stdout)
+		if (ch == stdout) {
+			of_node_put(ch_def);
 			ch_def = of_node_get(ch);
-		if (of_node_name_eq(ch, "ch-a"))
+		}
+		if (of_node_name_eq(ch, "ch-a")) {
+			of_node_put(ch_a);
 			ch_a = of_node_get(ch);
+		}
 	}
 	if (ch_def == NULL && !force_scc)
 		goto bail;