Skip to content

Commit 1dd7128

Browse files
Yuanzheng Songdlezcano
authored andcommitted
thermal/core: Fix null pointer dereference in thermal_release()
If both dev_set_name() and device_register() failed, then null pointer dereference occurs in thermal_release() which will use strncmp() to compare the name. So fix it by adding dev_set_name() return value check. Signed-off-by: Yuanzheng Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Daniel Lezcano <[email protected]>
1 parent c3131bd commit 1dd7128

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/thermal/thermal_core.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,10 @@ __thermal_cooling_device_register(struct device_node *np,
904904
goto out_kfree_cdev;
905905
cdev->id = ret;
906906

907+
ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
908+
if (ret)
909+
goto out_ida_remove;
910+
907911
cdev->type = kstrdup(type ? type : "", GFP_KERNEL);
908912
if (!cdev->type) {
909913
ret = -ENOMEM;
@@ -918,7 +922,6 @@ __thermal_cooling_device_register(struct device_node *np,
918922
cdev->device.class = &thermal_class;
919923
cdev->devdata = devdata;
920924
thermal_cooling_device_setup_sysfs(cdev);
921-
dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
922925
ret = device_register(&cdev->device);
923926
if (ret)
924927
goto out_kfree_type;
@@ -1229,6 +1232,10 @@ thermal_zone_device_register(const char *type, int trips, int mask,
12291232
tz->id = id;
12301233
strlcpy(tz->type, type, sizeof(tz->type));
12311234

1235+
result = dev_set_name(&tz->device, "thermal_zone%d", tz->id);
1236+
if (result)
1237+
goto remove_id;
1238+
12321239
if (!ops->critical)
12331240
ops->critical = thermal_zone_device_critical;
12341241

@@ -1250,7 +1257,6 @@ thermal_zone_device_register(const char *type, int trips, int mask,
12501257
/* A new thermal zone needs to be updated anyway. */
12511258
atomic_set(&tz->need_update, 1);
12521259

1253-
dev_set_name(&tz->device, "thermal_zone%d", tz->id);
12541260
result = device_register(&tz->device);
12551261
if (result)
12561262
goto release_device;

0 commit comments

Comments
 (0)