Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal: of: Use scoped device node handling to simplify of_thermal_zone_find()

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>

authored by

Krzysztof Kozlowski and committed by
Rafael J. Wysocki
8309135a a094ccfa

+6 -12
+6 -12
drivers/thermal/thermal_of.c
··· 125 125 126 126 static struct device_node *of_thermal_zone_find(struct device_node *sensor, int id) 127 127 { 128 - struct device_node *np, *tz; 129 128 struct of_phandle_args sensor_specs; 130 129 131 - np = of_find_node_by_name(NULL, "thermal-zones"); 130 + struct device_node *np __free(device_node) = of_find_node_by_name(NULL, "thermal-zones"); 132 131 if (!np) { 133 132 pr_debug("No thermal zones description\n"); 134 133 return ERR_PTR(-ENODEV); ··· 145 146 "#thermal-sensor-cells"); 146 147 if (count <= 0) { 147 148 pr_err("%pOFn: missing thermal sensor\n", child); 148 - tz = ERR_PTR(-EINVAL); 149 - goto out; 149 + return ERR_PTR(-EINVAL); 150 150 } 151 151 152 152 for (i = 0; i < count; i++) { ··· 157 159 i, &sensor_specs); 158 160 if (ret < 0) { 159 161 pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", child, ret); 160 - tz = ERR_PTR(ret); 161 - goto out; 162 + return ERR_PTR(ret); 162 163 } 163 164 164 165 if ((sensor == sensor_specs.np) && id == (sensor_specs.args_count ? 165 166 sensor_specs.args[0] : 0)) { 166 167 pr_debug("sensor %pOFn id=%d belongs to %pOFn\n", sensor, id, child); 167 - tz = no_free_ptr(child); 168 - goto out; 168 + return no_free_ptr(child); 169 169 } 170 170 } 171 171 } 172 - tz = ERR_PTR(-ENODEV); 173 - out: 174 - of_node_put(np); 175 - return tz; 172 + 173 + return ERR_PTR(-ENODEV); 176 174 } 177 175 178 176 static int thermal_of_monitor_init(struct device_node *np, int *delay, int *pdelay)