* [PATCH] of/irq: add missing of_node_put() for interrupt parent node
@ 2023-01-17 14:49 Clément Léger
2023-01-18 16:23 ` Rob Herring
2023-02-28 23:14 ` Rob Herring
0 siblings, 2 replies; 4+ messages in thread
From: Clément Léger @ 2023-01-17 14:49 UTC (permalink / raw)
To: Rob Herring, Frank Rowand
Cc: Clément Léger, devicetree, linux-kernel
After calling of_irq_parse_one(), the node provided in the of_phandle_args
has a refcount increment by one. Add missing of_node_put in of_irq_get()
to decrement the refcount once used.
Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
While debugging a refcount problem with OF_DYNAMIC enabled (which is
actually the only case were node refcount are really used), I noticed that
platform_get_irq() was actually incrementing the refcount of an interrupt
controller node. Digging into that function shows that it calls
of_irq_get() which calls of_irq_parse_one() and finally of_irq_parse_raw().
Since it seems sane that the node returned in the of_phandle_args has a
refcount incremented, I thought it is better to put the of_node_put() in
the user even though it was hard to find any user doing so.
drivers/of/irq.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index e9bf5236ed89..174900072c18 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -438,10 +438,16 @@ int of_irq_get(struct device_node *dev, int index)
return rc;
domain = irq_find_host(oirq.np);
- if (!domain)
- return -EPROBE_DEFER;
+ if (!domain) {
+ rc = -EPROBE_DEFER;
+ goto out;
+ }
- return irq_create_of_mapping(&oirq);
+ rc = irq_create_of_mapping(&oirq);
+out:
+ of_node_put(oirq.np);
+
+ return rc;
}
EXPORT_SYMBOL_GPL(of_irq_get);
--
2.39.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] of/irq: add missing of_node_put() for interrupt parent node
2023-01-17 14:49 [PATCH] of/irq: add missing of_node_put() for interrupt parent node Clément Léger
@ 2023-01-18 16:23 ` Rob Herring
2023-02-28 23:14 ` Rob Herring
1 sibling, 0 replies; 4+ messages in thread
From: Rob Herring @ 2023-01-18 16:23 UTC (permalink / raw)
To: Clément Léger
Cc: linux-kernel, Frank Rowand, Rob Herring, devicetree
On Tue, 17 Jan 2023 15:49:29 +0100, Clément Léger wrote:
> After calling of_irq_parse_one(), the node provided in the of_phandle_args
> has a refcount increment by one. Add missing of_node_put in of_irq_get()
> to decrement the refcount once used.
>
> Signed-off-by: Clément Léger <clement.leger@bootlin.com>
> ---
>
> While debugging a refcount problem with OF_DYNAMIC enabled (which is
> actually the only case were node refcount are really used), I noticed that
> platform_get_irq() was actually incrementing the refcount of an interrupt
> controller node. Digging into that function shows that it calls
> of_irq_get() which calls of_irq_parse_one() and finally of_irq_parse_raw().
> Since it seems sane that the node returned in the of_phandle_args has a
> refcount incremented, I thought it is better to put the of_node_put() in
> the user even though it was hard to find any user doing so.
>
> drivers/of/irq.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
Applied, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] of/irq: add missing of_node_put() for interrupt parent node
2023-01-17 14:49 [PATCH] of/irq: add missing of_node_put() for interrupt parent node Clément Léger
2023-01-18 16:23 ` Rob Herring
@ 2023-02-28 23:14 ` Rob Herring
2023-03-01 7:56 ` Clément Léger
1 sibling, 1 reply; 4+ messages in thread
From: Rob Herring @ 2023-02-28 23:14 UTC (permalink / raw)
To: Clément Léger, Saravana Kannan, Jean Jacques Hiblot
Cc: Frank Rowand, devicetree, linux-kernel
+Saravana, Jean
On Tue, Jan 17, 2023 at 8:47 AM Clément Léger <clement.leger@bootlin.com> wrote:
>
> After calling of_irq_parse_one(), the node provided in the of_phandle_args
> has a refcount increment by one. Add missing of_node_put in of_irq_get()
> to decrement the refcount once used.
>
> Signed-off-by: Clément Léger <clement.leger@bootlin.com>
> ---
>
> While debugging a refcount problem with OF_DYNAMIC enabled (which is
> actually the only case were node refcount are really used), I noticed that
> platform_get_irq() was actually incrementing the refcount of an interrupt
> controller node. Digging into that function shows that it calls
> of_irq_get() which calls of_irq_parse_one() and finally of_irq_parse_raw().
> Since it seems sane that the node returned in the of_phandle_args has a
> refcount incremented, I thought it is better to put the of_node_put() in
> the user even though it was hard to find any user doing so.
While investigating [1], I stumbled back on this. Was the failing case
you had using interrupts-extended? It looks to me like that path has a
get, but the 'interrupts' path does not. If so, this change is wrong.
Rob
[1] https://lore.kernel.org/all/20230228174019.4004581-1-jjhiblot@traphandler.com/
>
> drivers/of/irq.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/of/irq.c b/drivers/of/irq.c
> index e9bf5236ed89..174900072c18 100644
> --- a/drivers/of/irq.c
> +++ b/drivers/of/irq.c
> @@ -438,10 +438,16 @@ int of_irq_get(struct device_node *dev, int index)
> return rc;
>
> domain = irq_find_host(oirq.np);
> - if (!domain)
> - return -EPROBE_DEFER;
> + if (!domain) {
> + rc = -EPROBE_DEFER;
> + goto out;
> + }
>
> - return irq_create_of_mapping(&oirq);
> + rc = irq_create_of_mapping(&oirq);
> +out:
> + of_node_put(oirq.np);
> +
> + return rc;
> }
> EXPORT_SYMBOL_GPL(of_irq_get);
>
> --
> 2.39.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] of/irq: add missing of_node_put() for interrupt parent node
2023-02-28 23:14 ` Rob Herring
@ 2023-03-01 7:56 ` Clément Léger
0 siblings, 0 replies; 4+ messages in thread
From: Clément Léger @ 2023-03-01 7:56 UTC (permalink / raw)
To: Rob Herring
Cc: Saravana Kannan, Jean Jacques Hiblot, Frank Rowand, devicetree,
linux-kernel
Le Tue, 28 Feb 2023 17:14:18 -0600,
Rob Herring <robh+dt@kernel.org> a écrit :
> +Saravana, Jean
>
> On Tue, Jan 17, 2023 at 8:47 AM Clément Léger <clement.leger@bootlin.com> wrote:
> >
> > After calling of_irq_parse_one(), the node provided in the of_phandle_args
> > has a refcount increment by one. Add missing of_node_put in of_irq_get()
> > to decrement the refcount once used.
> >
> > Signed-off-by: Clément Léger <clement.leger@bootlin.com>
> > ---
> >
> > While debugging a refcount problem with OF_DYNAMIC enabled (which is
> > actually the only case were node refcount are really used), I noticed that
> > platform_get_irq() was actually incrementing the refcount of an interrupt
> > controller node. Digging into that function shows that it calls
> > of_irq_get() which calls of_irq_parse_one() and finally of_irq_parse_raw().
> > Since it seems sane that the node returned in the of_phandle_args has a
> > refcount incremented, I thought it is better to put the of_node_put() in
> > the user even though it was hard to find any user doing so.
>
> While investigating [1], I stumbled back on this. Was the failing case
> you had using interrupts-extended? It looks to me like that path has a
> get, but the 'interrupts' path does not. If so, this change is wrong.
In my case, it was with a classic "interrupts" property. I can take
another look at the internal code to be sure this fix is correct.
Clément
>
> Rob
>
> [1] https://lore.kernel.org/all/20230228174019.4004581-1-jjhiblot@traphandler.com/
>
>
> >
> > drivers/of/irq.c | 12 +++++++++---
> > 1 file changed, 9 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/of/irq.c b/drivers/of/irq.c
> > index e9bf5236ed89..174900072c18 100644
> > --- a/drivers/of/irq.c
> > +++ b/drivers/of/irq.c
> > @@ -438,10 +438,16 @@ int of_irq_get(struct device_node *dev, int index)
> > return rc;
> >
> > domain = irq_find_host(oirq.np);
> > - if (!domain)
> > - return -EPROBE_DEFER;
> > + if (!domain) {
> > + rc = -EPROBE_DEFER;
> > + goto out;
> > + }
> >
> > - return irq_create_of_mapping(&oirq);
> > + rc = irq_create_of_mapping(&oirq);
> > +out:
> > + of_node_put(oirq.np);
> > +
> > + return rc;
> > }
> > EXPORT_SYMBOL_GPL(of_irq_get);
> >
> > --
> > 2.39.0
> >
--
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-03-01 7:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-17 14:49 [PATCH] of/irq: add missing of_node_put() for interrupt parent node Clément Léger
2023-01-18 16:23 ` Rob Herring
2023-02-28 23:14 ` Rob Herring
2023-03-01 7:56 ` Clément Léger
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).