Skip to content

Commit

Permalink
thermal/of: Fix potential uninitialized value access
Browse files Browse the repository at this point in the history
[ Upstream commit f96801f ]

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 <peng.fan@nxp.com>
[ rjw: Subject and changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Peng Fan authored and Greg Kroah-Hartman committed Sep 13, 2023
1 parent 7c70932 commit 7da6250
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/thermal/thermal_of.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,13 @@ static int __thermal_of_unbind(struct device_node *map_np, int index, int trip_i
ret = of_parse_phandle_with_args(map_np, "cooling-device", "#cooling-cells",
index, &cooling_spec);

of_node_put(cooling_spec.np);

if (ret < 0) {
pr_err("Invalid cooling-device entry\n");
return ret;
}

of_node_put(cooling_spec.np);

if (cooling_spec.args_count < 2) {
pr_err("wrong reference to cooling device, missing limits\n");
return -EINVAL;
Expand All @@ -442,13 +442,13 @@ static int __thermal_of_bind(struct device_node *map_np, int index, int trip_id,
ret = of_parse_phandle_with_args(map_np, "cooling-device", "#cooling-cells",
index, &cooling_spec);

of_node_put(cooling_spec.np);

if (ret < 0) {
pr_err("Invalid cooling-device entry\n");
return ret;
}

of_node_put(cooling_spec.np);

if (cooling_spec.args_count < 2) {
pr_err("wrong reference to cooling device, missing limits\n");
return -EINVAL;
Expand Down

0 comments on commit 7da6250

Please sign in to comment.