Re: [PATCH 1/7] thermal: of: Use scoped device node handling to simplify of_find_trip_id()

Chen-Yu Tsai
2024-08-15T07:10:25Z

On Wed, Aug 14, 2024 at 10:17:47PM +0200, Krzysztof Kozlowski wrote:
> Obtain the device node reference with scoped/cleanup.h and use scoped
> for_each_child_of_node_scoped() to reduce error handling in
> of_find_trip_id() and make the code a bit simpler.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>

> ---
> drivers/thermal/thermal_of.c | 20 ++++++--------------
> 1 file changed, 6 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
> index 1f252692815a..a2278d4ad886 100644
> --- a/drivers/thermal/thermal_of.c
> +++ b/drivers/thermal/thermal_of.c
> @@ -8,6 +8,7 @@
>
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>
> +#include <linux/cleanup.h>
> #include <linux/err.h>
> #include <linux/export.h>
> #include <linux/of.h>
> @@ -22,11 +23,9 @@
>
> static int of_find_trip_id(struct device_node *np, struct device_node *trip)
> {
> - struct device_node *trips;
> - struct device_node *t;
> int i = 0;
>
> - trips = of_get_child_by_name(np, "trips");
> + struct device_node *trips __free(device_node) = of_get_child_by_name(np, "trips");
> if (!trips) {
> pr_err("Failed to find 'trips' node\n");
> return -EINVAL;
> @@ -35,20 +34,13 @@ static int of_find_trip_id(struct device_node *np, struct device_node *trip)
> /*
> * Find the trip id point associated with the cooling device map
> */
> - for_each_child_of_node(trips, t) {
> -
> - if (t == trip) {
> - of_node_put(t);
> - goto out;
> - }
> + for_each_child_of_node_scoped(trips, t) {
> + if (t == trip)
> + return i;
> i++;
> }
>
> - i = -ENXIO;
> -out:
> - of_node_put(trips);
> -
> - return i;
> + return -ENXIO;
> }
>
> /*
>
> --
> 2.43.0
>