Skip to content

Commit f771ed5

Browse files
krzkgregkh
authored andcommitted
thermal: of: Fix OF node leak in of_thermal_zone_find() error paths
commit c0a1ef9 upstream. 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: <stable@vger.kernel.org> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Reviewed-by: Chen-Yu Tsai <wenst@chromium.org> Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://patch.msgid.link/20240814195823.437597-3-krzysztof.kozlowski@linaro.org Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b6b864e commit f771ed5

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

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)