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

Subsystems: linux for power macintosh, linux for powerpc (32-bit and 64-bit), the rest

STALE1457d LANDED

Landed in mainline as 11373c933db2 on 2022-09-05.

4 messages, 3 authors, 2022-09-09 · open the first message on its own page

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

From: Liang He <hidden>
Date: 2022-07-16 07:32:26

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")
Signed-off-by: Liang He <redacted>
---
 arch/powerpc/platforms/powermac/pfunc_base.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/arch/powerpc/platforms/powermac/pfunc_base.c b/arch/powerpc/platforms/powermac/pfunc_base.c
index 9c2947a3edd5..085e0ad20eba 100644
--- a/arch/powerpc/platforms/powermac/pfunc_base.c
+++ b/arch/powerpc/platforms/powermac/pfunc_base.c
@@ -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
 	 */
-- 
2.25.1

Re: [PATCH] powerpc/powermac/pfunc_base: Fix refcount leak bug in macio_gpio_init_one()

From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: 2022-08-02 04:53:46

On Sat, 2022-07-16 at 15:31 +0800, Liang He wrote:
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 hunk
Fixes: 5b9ca526917b ("[PATCH] 3/5 powerpc: Add platform functions
interpreter")
Signed-off-by: Liang He <redacted>
---
 arch/powerpc/platforms/powermac/pfunc_base.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/arch/powerpc/platforms/powermac/pfunc_base.c
b/arch/powerpc/platforms/powermac/pfunc_base.c
index 9c2947a3edd5..085e0ad20eba 100644
--- a/arch/powerpc/platforms/powermac/pfunc_base.c
+++ b/arch/powerpc/platforms/powermac/pfunc_base.c
@@ -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
 	 */

Re:Re: [PATCH] powerpc/powermac/pfunc_base: Fix refcount leak bug in macio_gpio_init_one()

From: Liang He <hidden>
Date: 2022-08-13 12:12:34



At 2022-08-02 12:51:08, "Benjamin Herrenschmidt" [off-list ref] wrote:
On Sat, 2022-07-16 at 15:31 +0800, Liang He wrote:
quoted
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
Fixes: 5b9ca526917b ("[PATCH] 3/5 powerpc: Add platform functions
interpreter")
Signed-off-by: Liang He <redacted>
---
 arch/powerpc/platforms/powermac/pfunc_base.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/arch/powerpc/platforms/powermac/pfunc_base.c
b/arch/powerpc/platforms/powermac/pfunc_base.c
index 9c2947a3edd5..085e0ad20eba 100644
--- a/arch/powerpc/platforms/powermac/pfunc_base.c
+++ b/arch/powerpc/platforms/powermac/pfunc_base.c
@@ -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
 	 */

Re: [PATCH] powerpc/powermac/pfunc_base: Fix refcount leak bug in macio_gpio_init_one()

From: Michael Ellerman <hidden>
Date: 2022-09-09 12:20:45

On Sat, 16 Jul 2022 15:31:11 +0800, Liang He wrote:
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.
Applied to powerpc/next.

[1/1] powerpc/powermac/pfunc_base: Fix refcount leak bug in macio_gpio_init_one()
      https://git.kernel.org/powerpc/c/11373c933db20f8b6fd2cad27712e683ac9785f0

cheers
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help