Skip to content

Commit c0a1ef9

Browse files
krzkrafaeljw
authored andcommitted
thermal: of: Fix OF node leak in of_thermal_zone_find() error paths
Terminating for_each_available_child_of_node() loop requires dropping OF node reference, so bailing out on errors misses this. Solve the OF node reference leak with scoped for_each_available_child_of_node_scoped(). Fixes: 3fd6d6e ("thermal/of: Rework the thermal device tree initialization") Cc: <[email protected]> Signed-off-by: Krzysztof Kozlowski <[email protected]> Reviewed-by: Chen-Yu Tsai <[email protected]> Reviewed-by: Daniel Lezcano <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 662b52b commit c0a1ef9

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/thermal/thermal_of.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int
184184
* Search for each thermal zone, a defined sensor
185185
* corresponding to the one passed as parameter
186186
*/
187-
for_each_available_child_of_node(np, tz) {
187+
for_each_available_child_of_node_scoped(np, child) {
188188

189189
int count, i;
190190

191-
count = of_count_phandle_with_args(tz, "thermal-sensors",
191+
count = of_count_phandle_with_args(child, "thermal-sensors",
192192
"#thermal-sensor-cells");
193193
if (count <= 0) {
194-
pr_err("%pOFn: missing thermal sensor\n", tz);
194+
pr_err("%pOFn: missing thermal sensor\n", child);
195195
tz = ERR_PTR(-EINVAL);
196196
goto out;
197197
}
@@ -200,18 +200,19 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int
200200

201201
int ret;
202202

203-
ret = of_parse_phandle_with_args(tz, "thermal-sensors",
203+
ret = of_parse_phandle_with_args(child, "thermal-sensors",
204204
"#thermal-sensor-cells",
205205
i, &sensor_specs);
206206
if (ret < 0) {
207-
pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", tz, ret);
207+
pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", child, ret);
208208
tz = ERR_PTR(ret);
209209
goto out;
210210
}
211211

212212
if ((sensor == sensor_specs.np) && id == (sensor_specs.args_count ?
213213
sensor_specs.args[0] : 0)) {
214-
pr_debug("sensor %pOFn id=%d belongs to %pOFn\n", sensor, id, tz);
214+
pr_debug("sensor %pOFn id=%d belongs to %pOFn\n", sensor, id, child);
215+
tz = no_free_ptr(child);
215216
goto out;
216217
}
217218
}

0 commit comments

Comments
 (0)