* [PATCH] thermal/of: Fix reference leak in thermal_of_cm_lookup()
@ 2026-01-23 19:06 Felix Gu
2026-01-27 16:22 ` Rafael J. Wysocki
0 siblings, 1 reply; 4+ messages in thread
From: Felix Gu @ 2026-01-23 19:06 UTC (permalink / raw)
To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba, Yu-Che Cheng
Cc: Rafael J. Wysocki, linux-pm, linux-kernel, Felix Gu
In thermal_of_cm_lookup(), tr_np is obtained via of_parse_phandle(). But
it never be released.
Use the __free(device_node) cleanup attribute to automatically release
the node and fix the leak.
Fixes: 423de5b5bc5b ("thermal/of: Fix cdev lookup in thermal_of_should_bind()")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
drivers/thermal/thermal_of.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index 1a51a4d240ff..b6d0c92f5522 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -280,10 +280,10 @@ static bool thermal_of_cm_lookup(struct device_node *cm_np,
struct cooling_spec *c)
{
for_each_child_of_node_scoped(cm_np, child) {
- struct device_node *tr_np;
int count, i;
- tr_np = of_parse_phandle(child, "trip", 0);
+ struct device_node *tr_np __free(device_node) =
+ of_parse_phandle(child, "trip", 0);
if (tr_np != trip->priv)
continue;
---
base-commit: a0c666c25aeefd16f4b088c6549a6fb6b65a8a1d
change-id: 20260124-thermal_of-91774eece689
Best regards,
--
Felix Gu <ustc.gu@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] thermal/of: Fix reference leak in thermal_of_cm_lookup()
2026-01-23 19:06 [PATCH] thermal/of: Fix reference leak in thermal_of_cm_lookup() Felix Gu
@ 2026-01-27 16:22 ` Rafael J. Wysocki
2026-01-28 10:42 ` Lukasz Luba
0 siblings, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki @ 2026-01-27 16:22 UTC (permalink / raw)
To: Felix Gu, Daniel Lezcano, Lukasz Luba
Cc: Zhang Rui, Yu-Che Cheng, linux-pm, linux-kernel
On Fri, Jan 23, 2026 at 8:06 PM Felix Gu <ustc.gu@gmail.com> wrote:
>
> In thermal_of_cm_lookup(), tr_np is obtained via of_parse_phandle(). But
> it never be released.
> Use the __free(device_node) cleanup attribute to automatically release
> the node and fix the leak.
>
> Fixes: 423de5b5bc5b ("thermal/of: Fix cdev lookup in thermal_of_should_bind()")
>
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
> drivers/thermal/thermal_of.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
> index 1a51a4d240ff..b6d0c92f5522 100644
> --- a/drivers/thermal/thermal_of.c
> +++ b/drivers/thermal/thermal_of.c
> @@ -280,10 +280,10 @@ static bool thermal_of_cm_lookup(struct device_node *cm_np,
> struct cooling_spec *c)
> {
> for_each_child_of_node_scoped(cm_np, child) {
> - struct device_node *tr_np;
> int count, i;
>
> - tr_np = of_parse_phandle(child, "trip", 0);
> + struct device_node *tr_np __free(device_node) =
> + of_parse_phandle(child, "trip", 0);
> if (tr_np != trip->priv)
> continue;
>
>
> ---
This looks good to me.
Lukasz, Daniel?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] thermal/of: Fix reference leak in thermal_of_cm_lookup()
2026-01-27 16:22 ` Rafael J. Wysocki
@ 2026-01-28 10:42 ` Lukasz Luba
2026-01-28 21:11 ` Rafael J. Wysocki
0 siblings, 1 reply; 4+ messages in thread
From: Lukasz Luba @ 2026-01-28 10:42 UTC (permalink / raw)
To: Rafael J. Wysocki, Felix Gu
Cc: Zhang Rui, Yu-Che Cheng, Daniel Lezcano, linux-pm, linux-kernel
On 1/27/26 16:22, Rafael J. Wysocki wrote:
> On Fri, Jan 23, 2026 at 8:06 PM Felix Gu <ustc.gu@gmail.com> wrote:
>>
>> In thermal_of_cm_lookup(), tr_np is obtained via of_parse_phandle(). But
>> it never be released.
>> Use the __free(device_node) cleanup attribute to automatically release
>> the node and fix the leak.
>>
>> Fixes: 423de5b5bc5b ("thermal/of: Fix cdev lookup in thermal_of_should_bind()")
>>
>> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
>> ---
>> drivers/thermal/thermal_of.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
>> index 1a51a4d240ff..b6d0c92f5522 100644
>> --- a/drivers/thermal/thermal_of.c
>> +++ b/drivers/thermal/thermal_of.c
>> @@ -280,10 +280,10 @@ static bool thermal_of_cm_lookup(struct device_node *cm_np,
>> struct cooling_spec *c)
>> {
>> for_each_child_of_node_scoped(cm_np, child) {
>> - struct device_node *tr_np;
>> int count, i;
>>
>> - tr_np = of_parse_phandle(child, "trip", 0);
>> + struct device_node *tr_np __free(device_node) =
>> + of_parse_phandle(child, "trip", 0);
>> if (tr_np != trip->priv)
>> continue;
>>
>>
>> ---
>
> This looks good to me.
>
> Lukasz, Daniel?
Good catch thanks! That looks good. This scoped device node
handling approach simplifies a lot the error paths (and is less
error-prone).
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] thermal/of: Fix reference leak in thermal_of_cm_lookup()
2026-01-28 10:42 ` Lukasz Luba
@ 2026-01-28 21:11 ` Rafael J. Wysocki
0 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2026-01-28 21:11 UTC (permalink / raw)
To: Lukasz Luba, Felix Gu, Daniel Lezcano
Cc: Zhang Rui, Yu-Che Cheng, linux-pm, linux-kernel
On Wed, Jan 28, 2026 at 11:42 AM Lukasz Luba <lukasz.luba@arm.com> wrote:
>
>
>
> On 1/27/26 16:22, Rafael J. Wysocki wrote:
> > On Fri, Jan 23, 2026 at 8:06 PM Felix Gu <ustc.gu@gmail.com> wrote:
> >>
> >> In thermal_of_cm_lookup(), tr_np is obtained via of_parse_phandle(). But
> >> it never be released.
> >> Use the __free(device_node) cleanup attribute to automatically release
> >> the node and fix the leak.
> >>
> >> Fixes: 423de5b5bc5b ("thermal/of: Fix cdev lookup in thermal_of_should_bind()")
> >>
> >> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> >> ---
> >> drivers/thermal/thermal_of.c | 4 ++--
> >> 1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
> >> index 1a51a4d240ff..b6d0c92f5522 100644
> >> --- a/drivers/thermal/thermal_of.c
> >> +++ b/drivers/thermal/thermal_of.c
> >> @@ -280,10 +280,10 @@ static bool thermal_of_cm_lookup(struct device_node *cm_np,
> >> struct cooling_spec *c)
> >> {
> >> for_each_child_of_node_scoped(cm_np, child) {
> >> - struct device_node *tr_np;
> >> int count, i;
> >>
> >> - tr_np = of_parse_phandle(child, "trip", 0);
> >> + struct device_node *tr_np __free(device_node) =
> >> + of_parse_phandle(child, "trip", 0);
> >> if (tr_np != trip->priv)
> >> continue;
> >>
> >>
> >> ---
> >
> > This looks good to me.
> >
> > Lukasz, Daniel?
>
>
> Good catch thanks! That looks good. This scoped device node
> handling approach simplifies a lot the error paths (and is less
> error-prone).
>
> Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Applied as 6.20 material, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-28 21:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-23 19:06 [PATCH] thermal/of: Fix reference leak in thermal_of_cm_lookup() Felix Gu
2026-01-27 16:22 ` Rafael J. Wysocki
2026-01-28 10:42 ` Lukasz Luba
2026-01-28 21:11 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®