* [PATCH] arm/mach-omap2: Fix refcount leak bug in omap_hwmod.c
@ 2022-06-18 1:47 Liang He
2022-06-22 9:00 ` Krzysztof Kozlowski
2022-06-28 4:57 ` Tony Lindgren
0 siblings, 2 replies; 5+ messages in thread
From: Liang He @ 2022-06-18 1:47 UTC (permalink / raw)
To: tony, linux; +Cc: windhl, linux-omap, linux-arm-kernel, linux-kernel
In _init(), of_find_node_by_name() will return a node pointer with
refcount incremented. We should use of_node_put() in fail path or
when it is not used anymore.
NOTE: As the ref will be passed from 'bus' to 'np' by the xx_lookup(),
in normal exit path, we should call of_node_put() at the end use of 'np',
not the end use of 'bus'.
Signed-off-by: Liang He <windhl@126.com>
---
arch/arm/mach-omap2/omap_hwmod.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
index 31d1a21f6041..007e73cc0471 100644
--- a/arch/arm/mach-omap2/omap_hwmod.c
+++ b/arch/arm/mach-omap2/omap_hwmod.c
@@ -2365,6 +2365,7 @@ static int __init _init(struct omap_hwmod *oh, void *data)
r = _init_mpu_rt_base(oh, NULL, index, np);
if (r < 0) {
+ of_node_put(bus);
WARN(1, "omap_hwmod: %s: doesn't have mpu register target base\n",
oh->name);
return 0;
@@ -2372,6 +2373,7 @@ static int __init _init(struct omap_hwmod *oh, void *data)
r = _init_clocks(oh, np);
if (r < 0) {
+ of_node_put(bus);
WARN(1, "omap_hwmod: %s: couldn't init clocks\n", oh->name);
return -EINVAL;
}
@@ -2385,6 +2387,8 @@ static int __init _init(struct omap_hwmod *oh, void *data)
parse_module_flags(oh, child);
}
+ of_node_put(bus);
+
oh->_state = _HWMOD_STATE_INITIALIZED;
return 0;
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] arm/mach-omap2: Fix refcount leak bug in omap_hwmod.c
2022-06-18 1:47 [PATCH] arm/mach-omap2: Fix refcount leak bug in omap_hwmod.c Liang He
@ 2022-06-22 9:00 ` Krzysztof Kozlowski
2022-06-28 4:57 ` Tony Lindgren
1 sibling, 0 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2022-06-22 9:00 UTC (permalink / raw)
To: Liang He, tony, linux; +Cc: linux-omap, linux-arm-kernel, linux-kernel
On 18/06/2022 03:47, Liang He wrote:
> In _init(), of_find_node_by_name() will return a node pointer with
> refcount incremented. We should use of_node_put() in fail path or
> when it is not used anymore.
>
> NOTE: As the ref will be passed from 'bus' to 'np' by the xx_lookup(),
> in normal exit path, we should call of_node_put() at the end use of 'np',
> not the end use of 'bus'.
>
> Signed-off-by: Liang He <windhl@126.com>
> ---
> arch/arm/mach-omap2/omap_hwmod.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
Before applying the patch please check it carefully. Previous evidence
[1][2] suggests that not it was not even compiled.
[1] https://lore.kernel.org/all/202206221602.odN70SHs-lkp@intel.com/
[2]
https://lore.kernel.org/all/16f9a971.44e5.1817068ee3c.Coremail.windhl@126.com/
Best regards,
Krzysztof
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] arm/mach-omap2: Fix refcount leak bug in omap_hwmod.c
2022-06-18 1:47 [PATCH] arm/mach-omap2: Fix refcount leak bug in omap_hwmod.c Liang He
2022-06-22 9:00 ` Krzysztof Kozlowski
@ 2022-06-28 4:57 ` Tony Lindgren
2022-06-28 5:51 ` Liang He
1 sibling, 1 reply; 5+ messages in thread
From: Tony Lindgren @ 2022-06-28 4:57 UTC (permalink / raw)
To: Liang He; +Cc: linux, linux-omap, linux-arm-kernel, linux-kernel
Hi,
* Liang He <windhl@126.com> [220618 04:43]:
> In _init(), of_find_node_by_name() will return a node pointer with
> refcount incremented. We should use of_node_put() in fail path or
> when it is not used anymore.
>
> NOTE: As the ref will be passed from 'bus' to 'np' by the xx_lookup(),
> in normal exit path, we should call of_node_put() at the end use of 'np',
> not the end use of 'bus'.
Looks correct to me. What about missing of_node_put() for
of_get_next_child() also in the _init() function?
Regards,
Tony
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re:Re: [PATCH] arm/mach-omap2: Fix refcount leak bug in omap_hwmod.c
2022-06-28 4:57 ` Tony Lindgren
@ 2022-06-28 5:51 ` Liang He
2022-06-28 6:04 ` Tony Lindgren
0 siblings, 1 reply; 5+ messages in thread
From: Liang He @ 2022-06-28 5:51 UTC (permalink / raw)
To: Tony Lindgren; +Cc: linux, linux-omap, linux-arm-kernel, linux-kernel
At 2022-06-28 12:57:12, "Tony Lindgren" <tony@atomide.com> wrote:
>Hi,
>
>* Liang He <windhl@126.com> [220618 04:43]:
>> In _init(), of_find_node_by_name() will return a node pointer with
>> refcount incremented. We should use of_node_put() in fail path or
>> when it is not used anymore.
>>
>> NOTE: As the ref will be passed from 'bus' to 'np' by the xx_lookup(),
>> in normal exit path, we should call of_node_put() at the end use of 'np',
>> not the end use of 'bus'.
>
>Looks correct to me. What about missing of_node_put() for
>of_get_next_child() also in the _init() function?
>
>Regards,
>
>Tony
Thanks, Tony.
I have found this bug but not send the patch for of_get_next_child()
as I am collecting other OF function related bugs and I have been told that it is better
to collect all similar bugs in same directory, then finally report them.
So I will send a new patch for both of the two missing 'put' bugs caused by
of_find_xxx() and of_get_xxx() in omap_hwmod.c
Thanks gain.
Liang
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Re: [PATCH] arm/mach-omap2: Fix refcount leak bug in omap_hwmod.c
2022-06-28 5:51 ` Liang He
@ 2022-06-28 6:04 ` Tony Lindgren
0 siblings, 0 replies; 5+ messages in thread
From: Tony Lindgren @ 2022-06-28 6:04 UTC (permalink / raw)
To: Liang He; +Cc: linux, linux-omap, linux-arm-kernel, linux-kernel
* Liang He <windhl@126.com> [220628 05:47]:
>
>
> At 2022-06-28 12:57:12, "Tony Lindgren" <tony@atomide.com> wrote:
> >Hi,
> >
> >* Liang He <windhl@126.com> [220618 04:43]:
> >> In _init(), of_find_node_by_name() will return a node pointer with
> >> refcount incremented. We should use of_node_put() in fail path or
> >> when it is not used anymore.
> >>
> >> NOTE: As the ref will be passed from 'bus' to 'np' by the xx_lookup(),
> >> in normal exit path, we should call of_node_put() at the end use of 'np',
> >> not the end use of 'bus'.
> >
> >Looks correct to me. What about missing of_node_put() for
> >of_get_next_child() also in the _init() function?
> >
> >Regards,
> >
> >Tony
>
> Thanks, Tony.
>
> I have found this bug but not send the patch for of_get_next_child()
> as I am collecting other OF function related bugs and I have been told that it is better
> to collect all similar bugs in same directory, then finally report them.
Well in this case while you review a single function, it's usually better
to fix similar issues to avoid having to review the same function multiple
times. Of course if the patch becomes hard to read, then it makes sense
to split it into several patches.
> So I will send a new patch for both of the two missing 'put' bugs caused by
> of_find_xxx() and of_get_xxx() in omap_hwmod.c
Please just update this patch so we have _init() completely reviewed for
similar issues and is not left only partially patched.
Regards,
Tony
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-06-28 6:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-18 1:47 [PATCH] arm/mach-omap2: Fix refcount leak bug in omap_hwmod.c Liang He
2022-06-22 9:00 ` Krzysztof Kozlowski
2022-06-28 4:57 ` Tony Lindgren
2022-06-28 5:51 ` Liang He
2022-06-28 6:04 ` Tony Lindgren
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).