diff mbox series

[v2,4/7] thermal: of: Simplify thermal_of_for_each_cooling_maps() with scoped for each OF child loop

Message ID 20240816-b4-cleanup-h-of-node-put-thermal-v2-4-cee9fc490478@linaro.org (mailing list archive)
State Not Applicable, archived
Headers show
Series thermal: scope/cleanup.h improvements | expand

Commit Message

Krzysztof Kozlowski Aug. 16, 2024, 7:40 a.m. UTC
Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.

Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/thermal/thermal_of.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Rafael J. Wysocki Aug. 16, 2024, 11:30 a.m. UTC | #1
On Fri, Aug 16, 2024 at 9:40 AM Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
>
> Use scoped for_each_child_of_node_scoped() when iterating over device
> nodes to make code a bit simpler.
>
> Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>  drivers/thermal/thermal_of.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
> index 94cc077ab3a1..ce398fde48bb 100644
> --- a/drivers/thermal/thermal_of.c
> +++ b/drivers/thermal/thermal_of.c
> @@ -373,7 +373,7 @@ static int thermal_of_for_each_cooling_maps(struct thermal_zone_device *tz,
>                                             int (*action)(struct device_node *, int, int,
>                                                           struct thermal_zone_device *, struct thermal_cooling_device *))
>  {
> -       struct device_node *tz_np, *cm_np, *child;
> +       struct device_node *tz_np, *cm_np;
>         int ret = 0;
>
>         tz_np = thermal_of_zone_get_by_name(tz);
> @@ -386,12 +386,10 @@ static int thermal_of_for_each_cooling_maps(struct thermal_zone_device *tz,
>         if (!cm_np)
>                 goto out;
>
> -       for_each_child_of_node(cm_np, child) {
> +       for_each_child_of_node_scoped(cm_np, child) {
>                 ret = thermal_of_for_each_cooling_device(tz_np, child, tz, cdev, action);
> -               if (ret) {
> -                       of_node_put(child);
> +               if (ret)
>                         break;
> -               }
>         }
>
>         of_node_put(cm_np);
>
> --

This clashes with

https://lore.kernel.org/linux-pm/1758256.QkHrqEjB74@rjwysocki.net/

which I would prefer to go in first if you don't mind.
Krzysztof Kozlowski Aug. 16, 2024, 12:21 p.m. UTC | #2
On 16/08/2024 13:30, Rafael J. Wysocki wrote:
> On Fri, Aug 16, 2024 at 9:40 AM Krzysztof Kozlowski
> <krzysztof.kozlowski@linaro.org> wrote:
>>
>> Use scoped for_each_child_of_node_scoped() when iterating over device
>> nodes to make code a bit simpler.
>>
>> Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>> ---
>>  drivers/thermal/thermal_of.c | 8 +++-----
>>  1 file changed, 3 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
>> index 94cc077ab3a1..ce398fde48bb 100644
>> --- a/drivers/thermal/thermal_of.c
>> +++ b/drivers/thermal/thermal_of.c
>> @@ -373,7 +373,7 @@ static int thermal_of_for_each_cooling_maps(struct thermal_zone_device *tz,
>>                                             int (*action)(struct device_node *, int, int,
>>                                                           struct thermal_zone_device *, struct thermal_cooling_device *))
>>  {
>> -       struct device_node *tz_np, *cm_np, *child;
>> +       struct device_node *tz_np, *cm_np;
>>         int ret = 0;
>>
>>         tz_np = thermal_of_zone_get_by_name(tz);
>> @@ -386,12 +386,10 @@ static int thermal_of_for_each_cooling_maps(struct thermal_zone_device *tz,
>>         if (!cm_np)
>>                 goto out;
>>
>> -       for_each_child_of_node(cm_np, child) {
>> +       for_each_child_of_node_scoped(cm_np, child) {
>>                 ret = thermal_of_for_each_cooling_device(tz_np, child, tz, cdev, action);
>> -               if (ret) {
>> -                       of_node_put(child);
>> +               if (ret)
>>                         break;
>> -               }
>>         }
>>
>>         of_node_put(cm_np);
>>
>> --
> 
> This clashes with
> 
> https://lore.kernel.org/linux-pm/1758256.QkHrqEjB74@rjwysocki.net/
> 
> which I would prefer to go in first if you don't mind.

My other patchset which fixes bugs here, could go in before:
https://lore.kernel.org/all/20240814195823.437597-1-krzysztof.kozlowski@linaro.org/

so it will be backported. Other than that, I am fine with rebasing my
changes. There is no point in refactoring the code if it is being
removed/reshuffled :)

Best regards,
Krzysztof
Rafael J. Wysocki Aug. 16, 2024, 4:02 p.m. UTC | #3
On Fri, Aug 16, 2024 at 2:22 PM Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
>
> On 16/08/2024 13:30, Rafael J. Wysocki wrote:
> > On Fri, Aug 16, 2024 at 9:40 AM Krzysztof Kozlowski
> > <krzysztof.kozlowski@linaro.org> wrote:
> >>
> >> Use scoped for_each_child_of_node_scoped() when iterating over device
> >> nodes to make code a bit simpler.
> >>
> >> Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
> >> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> >> ---
> >>  drivers/thermal/thermal_of.c | 8 +++-----
> >>  1 file changed, 3 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
> >> index 94cc077ab3a1..ce398fde48bb 100644
> >> --- a/drivers/thermal/thermal_of.c
> >> +++ b/drivers/thermal/thermal_of.c
> >> @@ -373,7 +373,7 @@ static int thermal_of_for_each_cooling_maps(struct thermal_zone_device *tz,
> >>                                             int (*action)(struct device_node *, int, int,
> >>                                                           struct thermal_zone_device *, struct thermal_cooling_device *))
> >>  {
> >> -       struct device_node *tz_np, *cm_np, *child;
> >> +       struct device_node *tz_np, *cm_np;
> >>         int ret = 0;
> >>
> >>         tz_np = thermal_of_zone_get_by_name(tz);
> >> @@ -386,12 +386,10 @@ static int thermal_of_for_each_cooling_maps(struct thermal_zone_device *tz,
> >>         if (!cm_np)
> >>                 goto out;
> >>
> >> -       for_each_child_of_node(cm_np, child) {
> >> +       for_each_child_of_node_scoped(cm_np, child) {
> >>                 ret = thermal_of_for_each_cooling_device(tz_np, child, tz, cdev, action);
> >> -               if (ret) {
> >> -                       of_node_put(child);
> >> +               if (ret)
> >>                         break;
> >> -               }
> >>         }
> >>
> >>         of_node_put(cm_np);
> >>
> >> --
> >
> > This clashes with
> >
> > https://lore.kernel.org/linux-pm/1758256.QkHrqEjB74@rjwysocki.net/
> >
> > which I would prefer to go in first if you don't mind.
>
> My other patchset which fixes bugs here, could go in before:
> https://lore.kernel.org/all/20240814195823.437597-1-krzysztof.kozlowski@linaro.org/

Right, but these don't clash significantly if I'm not mistaken.

It may make sense to push them for 6.11-rc even.

> so it will be backported. Other than that, I am fine with rebasing my
> changes. There is no point in refactoring the code if it is being
> removed/reshuffled :)

OK
diff mbox series

Patch

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index 94cc077ab3a1..ce398fde48bb 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -373,7 +373,7 @@  static int thermal_of_for_each_cooling_maps(struct thermal_zone_device *tz,
 					    int (*action)(struct device_node *, int, int,
 							  struct thermal_zone_device *, struct thermal_cooling_device *))
 {
-	struct device_node *tz_np, *cm_np, *child;
+	struct device_node *tz_np, *cm_np;
 	int ret = 0;
 
 	tz_np = thermal_of_zone_get_by_name(tz);
@@ -386,12 +386,10 @@  static int thermal_of_for_each_cooling_maps(struct thermal_zone_device *tz,
 	if (!cm_np)
 		goto out;
 
-	for_each_child_of_node(cm_np, child) {
+	for_each_child_of_node_scoped(cm_np, child) {
 		ret = thermal_of_for_each_cooling_device(tz_np, child, tz, cdev, action);
-		if (ret) {
-			of_node_put(child);
+		if (ret)
 			break;
-		}
 	}
 
 	of_node_put(cm_np);