]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
thermal: of: Use scoped device node handling to simplify of_thermal_zone_find()
authorKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Thu, 10 Oct 2024 18:06:19 +0000 (20:06 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 26 Nov 2024 12:28:43 +0000 (13:28 +0100)
Obtain the device node reference with scoped/cleanup.h to reduce error
handling and make the code a bit simpler.

Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://patch.msgid.link/20241010-b4-cleanup-h-of-node-put-thermal-v4-3-bfbe29ad81f4@linaro.org
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/thermal/thermal_of.c

index 9b0a3ec36a9035992de1a1d6ec824875a82db94e..fab11b98ca4952d23d0232998433bd0650b53d24 100644 (file)
@@ -125,10 +125,9 @@ static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *n
 
 static struct device_node *of_thermal_zone_find(struct device_node *sensor, int id)
 {
-       struct device_node *np, *tz;
        struct of_phandle_args sensor_specs;
 
-       np = of_find_node_by_name(NULL, "thermal-zones");
+       struct device_node *np __free(device_node) = of_find_node_by_name(NULL, "thermal-zones");
        if (!np) {
                pr_debug("No thermal zones description\n");
                return ERR_PTR(-ENODEV);
@@ -146,8 +145,7 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int
                                                   "#thermal-sensor-cells");
                if (count <= 0) {
                        pr_err("%pOFn: missing thermal sensor\n", child);
-                       tz = ERR_PTR(-EINVAL);
-                       goto out;
+                       return ERR_PTR(-EINVAL);
                }
 
                for (i = 0; i < count; i++) {
@@ -159,22 +157,18 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int
                                                         i, &sensor_specs);
                        if (ret < 0) {
                                pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", child, ret);
-                               tz = ERR_PTR(ret);
-                               goto out;
+                               return ERR_PTR(ret);
                        }
 
                        if ((sensor == sensor_specs.np) && id == (sensor_specs.args_count ?
                                                                  sensor_specs.args[0] : 0)) {
                                pr_debug("sensor %pOFn id=%d belongs to %pOFn\n", sensor, id, child);
-                               tz = no_free_ptr(child);
-                               goto out;
+                               return no_free_ptr(child);
                        }
                }
        }
-       tz = ERR_PTR(-ENODEV);
-out:
-       of_node_put(np);
-       return tz;
+
+       return ERR_PTR(-ENODEV);
 }
 
 static int thermal_of_monitor_init(struct device_node *np, int *delay, int *pdelay)