* [PATCH] powerpc/flipper-pic: Fix device node reference leak in flipper_pic_init
@ 2025-10-27 15:09 Miaoqian Lin
2025-11-04 17:26 ` Christophe Leroy
0 siblings, 1 reply; 2+ messages in thread
From: Miaoqian Lin @ 2025-10-27 15:09 UTC (permalink / raw)
To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Jiri Slaby (SUSE), Thomas Gleixner,
Albert Herranz, Grant Likely, Segher Boessenkool, linuxppc-dev,
linux-kernel
Cc: linmq006, stable
The flipper_pic_init() function calls of_get_parent() which increases
the device node reference count, but fails to call of_node_put() to
balance the reference count.
Add calls to of_node_put() in all paths to fix the leak.
Found via static analysis.
Fixes: 028ee972f032 ("powerpc: gamecube/wii: flipper interrupt controller support")
Cc: stable@vger.kernel.org
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
arch/powerpc/platforms/embedded6xx/flipper-pic.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/platforms/embedded6xx/flipper-pic.c b/arch/powerpc/platforms/embedded6xx/flipper-pic.c
index 91a8f0a7086e..cf6f795c8d76 100644
--- a/arch/powerpc/platforms/embedded6xx/flipper-pic.c
+++ b/arch/powerpc/platforms/embedded6xx/flipper-pic.c
@@ -135,13 +135,13 @@ static struct irq_domain * __init flipper_pic_init(struct device_node *np)
}
if (!of_device_is_compatible(pi, "nintendo,flipper-pi")) {
pr_err("unexpected parent compatible\n");
- goto out;
+ goto out_put_node;
}
retval = of_address_to_resource(pi, 0, &res);
if (retval) {
pr_err("no io memory range found\n");
- goto out;
+ goto out_put_node;
}
io_base = ioremap(res.start, resource_size(&res));
@@ -154,9 +154,12 @@ static struct irq_domain * __init flipper_pic_init(struct device_node *np)
&flipper_irq_domain_ops, io_base);
if (!irq_domain) {
pr_err("failed to allocate irq_domain\n");
+ of_node_put(pi);
return NULL;
}
+out_put_node:
+ of_node_put(pi);
out:
return irq_domain;
}
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] powerpc/flipper-pic: Fix device node reference leak in flipper_pic_init
2025-10-27 15:09 [PATCH] powerpc/flipper-pic: Fix device node reference leak in flipper_pic_init Miaoqian Lin
@ 2025-11-04 17:26 ` Christophe Leroy
0 siblings, 0 replies; 2+ messages in thread
From: Christophe Leroy @ 2025-11-04 17:26 UTC (permalink / raw)
To: Miaoqian Lin, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Jiri Slaby (SUSE), Thomas Gleixner,
Albert Herranz, Grant Likely, Segher Boessenkool, linuxppc-dev,
linux-kernel
Cc: stable
Le 27/10/2025 à 16:09, Miaoqian Lin a écrit :
> The flipper_pic_init() function calls of_get_parent() which increases
> the device node reference count, but fails to call of_node_put() to
> balance the reference count.
>
> Add calls to of_node_put() in all paths to fix the leak.
>
> Found via static analysis.
>
> Fixes: 028ee972f032 ("powerpc: gamecube/wii: flipper interrupt controller support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> arch/powerpc/platforms/embedded6xx/flipper-pic.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/platforms/embedded6xx/flipper-pic.c b/arch/powerpc/platforms/embedded6xx/flipper-pic.c
> index 91a8f0a7086e..cf6f795c8d76 100644
> --- a/arch/powerpc/platforms/embedded6xx/flipper-pic.c
> +++ b/arch/powerpc/platforms/embedded6xx/flipper-pic.c
> @@ -135,13 +135,13 @@ static struct irq_domain * __init flipper_pic_init(struct device_node *np)
> }
> if (!of_device_is_compatible(pi, "nintendo,flipper-pi")) {
> pr_err("unexpected parent compatible\n");
> - goto out;
> + goto out_put_node;
> }
>
> retval = of_address_to_resource(pi, 0, &res);
> if (retval) {
> pr_err("no io memory range found\n");
> - goto out;
> + goto out_put_node;
> }
> io_base = ioremap(res.start, resource_size(&res));
>
> @@ -154,9 +154,12 @@ static struct irq_domain * __init flipper_pic_init(struct device_node *np)
> &flipper_irq_domain_ops, io_base);
> if (!irq_domain) {
> pr_err("failed to allocate irq_domain\n");
> + of_node_put(pi);
irq_domain is NULL here so instead of adding this of_node_put() you
could just remove below 'return NULL' (and the {} of the if) and
fallthrough.
> return NULL;
> }
>
> +out_put_node:
> + of_node_put(pi);
> out:
> return irq_domain;
> }
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-11-04 17:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-27 15:09 [PATCH] powerpc/flipper-pic: Fix device node reference leak in flipper_pic_init Miaoqian Lin
2025-11-04 17:26 ` Christophe Leroy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).