Skip to contentSkip to conversation

powerpc/powermac/pfunc_base: Fix refcount leak bug in macio_gpio_init_one()

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

Subsystems (2)
lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 powerpc/powermac/pfunc_base: Fix refcount leak bug in macio_gpio_init_one()

We should call of_node_put() for the reference 'gparent' escaped out of the for_each_child_of_node() as it has increased the refcount.

Fixes 5b9ca526917b ("[PATCH] 3/5 powerpc: Add platform functions interpreter")
---
 arch/powerpc/platforms/powermac/pfunc_base.c | 2 ++
 1 file changed, 2 insertions(+)
arch/powerpc/platforms/powermac/pfunc_base.c +2 -0
index 9c2947a3edd5..085e0ad20eba 100644
@@ -136,6 +136,8 @@ static void __init macio_gpio_init_one(struct macio_chip *macio)
 	for_each_child_of_node(gparent, gp)
 		pmf_do_functions(gp, NULL, 0, PMF_FLAGS_ON_INIT, NULL);
 
+	of_node_put(gparent);
+
 	/* Note: We do not at this point implement the "at sleep" or "at wake"
 	 * functions. I yet to find any for GPIOs anyway
 	 */
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines · Liang He

We should call of_node_put() for the reference 'gparent' escaped out of the for_each_child_of_node() as it has increased the refcount.

Same comment as before. That stuff happens once at boot, there's never any dynamic allocation/deallocation of these, they just don't matter, but feel free .... :-)

Quoted 23 lines
Fixes 5b9ca526917b ("[PATCH] 3/5 powerpc: Add platform functions

interpreter")

---
 arch/powerpc/platforms/powermac/pfunc_base.c | 2 ++
 1 file changed, 2 insertions(+)
arch/powerpc/platforms/powermac/pfunc_base.c +2 -0
index 9c2947a3edd5..085e0ad20eba 100644
@@ -136,6 +136,8 @@ static void __init macio_gpio_init_one(struct
 macio_chip *macio)
 	for_each_child_of_node(gparent, gp)
 		pmf_do_functions(gp, NULL, 0, PMF_FLAGS_ON_INIT, NULL);
 
+	of_node_put(gparent);
+
 	/* Note: We do not at this point implement the "at sleep" or

"at wake"

arch/powerpc/platforms/powermac/pfunc_base.c +0 -0
 	 * functions. I yet to find any for GPIOs anyway
 	 */
author
#2 lore raw
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 2 lines · Liang He

We should call of_node_put() for the reference 'gparent' escaped out of the for_each_child_of_node() as it has increased the refcount.

Same comment as before. That stuff happens once at boot, there's never any dynamic allocation/deallocation of these, they just don't matter, but feel free .... :-)

Thanks for your reply, this is a valuable lesson for me.
I will now begin to learn the detailed difference of dynamic and static allocation.

Thanks,
Liang

Quoted 23 lines
Quoted 23 lines
Fixes 5b9ca526917b ("[PATCH] 3/5 powerpc: Add platform functions

interpreter")

---
 arch/powerpc/platforms/powermac/pfunc_base.c | 2 ++
 1 file changed, 2 insertions(+)
arch/powerpc/platforms/powermac/pfunc_base.c +2 -0
index 9c2947a3edd5..085e0ad20eba 100644
@@ -136,6 +136,8 @@ static void __init macio_gpio_init_one(struct
 macio_chip *macio)
 	for_each_child_of_node(gparent, gp)
 		pmf_do_functions(gp, NULL, 0, PMF_FLAGS_ON_INIT, NULL);
 
+	of_node_put(gparent);
+
 	/* Note: We do not at this point implement the "at sleep" or

"at wake"

arch/powerpc/platforms/powermac/pfunc_base.c +0 -0
 	 * functions. I yet to find any for GPIOs anyway
 	 */