Skip to content

Commit f96801f

Browse files
MrVanrafaeljw
authored andcommitted
thermal/of: Fix potential uninitialized value access
If of_parse_phandle_with_args() called from __thermal_of_bind() or __thermal_of_unbind() fails, cooling_spec.np will not be initialized, so move the of_node_put() calls below the respective return value checks to avoid dereferencing an uninitialized pointer. Fixes: 3fd6d6e ("thermal/of: Rework the thermal device tree initialization") Signed-off-by: Peng Fan <[email protected]> [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent b616959 commit f96801f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/thermal/thermal_of.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,13 @@ static int __thermal_of_unbind(struct device_node *map_np, int index, int trip_i
291291
ret = of_parse_phandle_with_args(map_np, "cooling-device", "#cooling-cells",
292292
index, &cooling_spec);
293293

294-
of_node_put(cooling_spec.np);
295-
296294
if (ret < 0) {
297295
pr_err("Invalid cooling-device entry\n");
298296
return ret;
299297
}
300298

299+
of_node_put(cooling_spec.np);
300+
301301
if (cooling_spec.args_count < 2) {
302302
pr_err("wrong reference to cooling device, missing limits\n");
303303
return -EINVAL;
@@ -324,13 +324,13 @@ static int __thermal_of_bind(struct device_node *map_np, int index, int trip_id,
324324
ret = of_parse_phandle_with_args(map_np, "cooling-device", "#cooling-cells",
325325
index, &cooling_spec);
326326

327-
of_node_put(cooling_spec.np);
328-
329327
if (ret < 0) {
330328
pr_err("Invalid cooling-device entry\n");
331329
return ret;
332330
}
333331

332+
of_node_put(cooling_spec.np);
333+
334334
if (cooling_spec.args_count < 2) {
335335
pr_err("wrong reference to cooling device, missing limits\n");
336336
return -EINVAL;

0 commit comments

Comments
 (0)