Skip to content

Commit 6ae4e48

Browse files
committed
Merge tag 'thermal-6.11-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull thermal control fixes from Rafael Wysocki: "These fix error handling in the thermal debug code and OF node reference leaks in the thermal OF driver. Specifics: - Use IS_ERR() in checks of debugfs_create_dir() return value instead of checking it against NULL in the thermal debug code (Yang Ruibin) - Fix three OF node reference leaks in thermal_of (Krzysztof Kozlowski)" * tag 'thermal-6.11-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: thermal: of: Fix OF node leak in of_thermal_zone_find() error paths thermal: of: Fix OF node leak in thermal_of_zone_register() thermal: of: Fix OF node leak in thermal_of_trips_init() error path thermal/debugfs: Fix the NULL vs IS_ERR() confusion in debugfs_create_dir()
2 parents f76a30a + c0a1ef9 commit 6ae4e48

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

drivers/thermal/thermal_debugfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@ struct thermal_debugfs {
178178
void thermal_debug_init(void)
179179
{
180180
d_root = debugfs_create_dir("thermal", NULL);
181-
if (!d_root)
181+
if (IS_ERR(d_root))
182182
return;
183183

184184
d_cdev = debugfs_create_dir("cooling_devices", d_root);
185-
if (!d_cdev)
185+
if (IS_ERR(d_cdev))
186186
return;
187187

188188
d_tz = debugfs_create_dir("thermal_zones", d_root);
@@ -202,7 +202,7 @@ static struct thermal_debugfs *thermal_debugfs_add_id(struct dentry *d, int id)
202202
snprintf(ids, IDSLENGTH, "%d", id);
203203

204204
thermal_dbg->d_top = debugfs_create_dir(ids, d);
205-
if (!thermal_dbg->d_top) {
205+
if (IS_ERR(thermal_dbg->d_top)) {
206206
kfree(thermal_dbg);
207207
return NULL;
208208
}

drivers/thermal/thermal_of.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static int thermal_of_populate_trip(struct device_node *np,
125125
static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *ntrips)
126126
{
127127
struct thermal_trip *tt;
128-
struct device_node *trips, *trip;
128+
struct device_node *trips;
129129
int ret, count;
130130

131131
trips = of_get_child_by_name(np, "trips");
@@ -150,7 +150,7 @@ static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *n
150150
*ntrips = count;
151151

152152
count = 0;
153-
for_each_child_of_node(trips, trip) {
153+
for_each_child_of_node_scoped(trips, trip) {
154154
ret = thermal_of_populate_trip(trip, &tt[count++]);
155155
if (ret)
156156
goto out_kfree;
@@ -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
}
@@ -491,7 +492,8 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node *
491492
trips = thermal_of_trips_init(np, &ntrips);
492493
if (IS_ERR(trips)) {
493494
pr_err("Failed to find trip points for %pOFn id=%d\n", sensor, id);
494-
return ERR_CAST(trips);
495+
ret = PTR_ERR(trips);
496+
goto out_of_node_put;
495497
}
496498

497499
ret = thermal_of_monitor_init(np, &delay, &pdelay);
@@ -519,6 +521,7 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node *
519521
goto out_kfree_trips;
520522
}
521523

524+
of_node_put(np);
522525
kfree(trips);
523526

524527
ret = thermal_zone_device_enable(tz);
@@ -533,6 +536,8 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node *
533536

534537
out_kfree_trips:
535538
kfree(trips);
539+
out_of_node_put:
540+
of_node_put(np);
536541

537542
return ERR_PTR(ret);
538543
}

0 commit comments

Comments
 (0)