Skip to content

Commit 4748f96

Browse files
Yang Yingliangrafaeljw
authored andcommitted
thermal: core: fix some possible name leaks in error paths
In some error paths before device_register(), the names allocated by dev_set_name() are not freed. Move dev_set_name() front to device_register(), so the name can be freed while calling put_device(). Fixes: 1dd7128 ("thermal/core: Fix null pointer dereference in thermal_release()") Signed-off-by: Yang Yingliang <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent b778b4d commit 4748f96

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

drivers/thermal/thermal_core.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -894,10 +894,6 @@ __thermal_cooling_device_register(struct device_node *np,
894894
cdev->id = ret;
895895
id = ret;
896896

897-
ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
898-
if (ret)
899-
goto out_ida_remove;
900-
901897
cdev->type = kstrdup(type ? type : "", GFP_KERNEL);
902898
if (!cdev->type) {
903899
ret = -ENOMEM;
@@ -917,6 +913,11 @@ __thermal_cooling_device_register(struct device_node *np,
917913
goto out_kfree_type;
918914

919915
thermal_cooling_device_setup_sysfs(cdev);
916+
ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
917+
if (ret) {
918+
thermal_cooling_device_destroy_sysfs(cdev);
919+
goto out_kfree_type;
920+
}
920921
ret = device_register(&cdev->device);
921922
if (ret)
922923
goto out_kfree_type;
@@ -1250,10 +1251,6 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
12501251
tz->id = id;
12511252
strscpy(tz->type, type, sizeof(tz->type));
12521253

1253-
result = dev_set_name(&tz->device, "thermal_zone%d", tz->id);
1254-
if (result)
1255-
goto remove_id;
1256-
12571254
if (!ops->critical)
12581255
ops->critical = thermal_zone_device_critical;
12591256

@@ -1276,6 +1273,11 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
12761273
/* A new thermal zone needs to be updated anyway. */
12771274
atomic_set(&tz->need_update, 1);
12781275

1276+
result = dev_set_name(&tz->device, "thermal_zone%d", tz->id);
1277+
if (result) {
1278+
thermal_zone_destroy_device_groups(tz);
1279+
goto remove_id;
1280+
}
12791281
result = device_register(&tz->device);
12801282
if (result)
12811283
goto release_device;

0 commit comments

Comments
 (0)