Commit 1dd7128b authored by Yuanzheng Song's avatar Yuanzheng Song Committed by Daniel Lezcano

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: default avatarYuanzheng Song <songyuanzheng@huawei.com>
Link: https://lore.kernel.org/r/20211015083230.67658-1-songyuanzheng@huawei.comSigned-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
parent c3131bd5
...@@ -904,6 +904,10 @@ __thermal_cooling_device_register(struct device_node *np, ...@@ -904,6 +904,10 @@ __thermal_cooling_device_register(struct device_node *np,
goto out_kfree_cdev; goto out_kfree_cdev;
cdev->id = ret; cdev->id = ret;
ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
if (ret)
goto out_ida_remove;
cdev->type = kstrdup(type ? type : "", GFP_KERNEL); cdev->type = kstrdup(type ? type : "", GFP_KERNEL);
if (!cdev->type) { if (!cdev->type) {
ret = -ENOMEM; ret = -ENOMEM;
...@@ -918,7 +922,6 @@ __thermal_cooling_device_register(struct device_node *np, ...@@ -918,7 +922,6 @@ __thermal_cooling_device_register(struct device_node *np,
cdev->device.class = &thermal_class; cdev->device.class = &thermal_class;
cdev->devdata = devdata; cdev->devdata = devdata;
thermal_cooling_device_setup_sysfs(cdev); thermal_cooling_device_setup_sysfs(cdev);
dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
ret = device_register(&cdev->device); ret = device_register(&cdev->device);
if (ret) if (ret)
goto out_kfree_type; goto out_kfree_type;
...@@ -1229,6 +1232,10 @@ thermal_zone_device_register(const char *type, int trips, int mask, ...@@ -1229,6 +1232,10 @@ thermal_zone_device_register(const char *type, int trips, int mask,
tz->id = id; tz->id = id;
strlcpy(tz->type, type, sizeof(tz->type)); strlcpy(tz->type, type, sizeof(tz->type));
result = dev_set_name(&tz->device, "thermal_zone%d", tz->id);
if (result)
goto remove_id;
if (!ops->critical) if (!ops->critical)
ops->critical = thermal_zone_device_critical; ops->critical = thermal_zone_device_critical;
...@@ -1250,7 +1257,6 @@ thermal_zone_device_register(const char *type, int trips, int mask, ...@@ -1250,7 +1257,6 @@ thermal_zone_device_register(const char *type, int trips, int mask,
/* A new thermal zone needs to be updated anyway. */ /* A new thermal zone needs to be updated anyway. */
atomic_set(&tz->need_update, 1); atomic_set(&tz->need_update, 1);
dev_set_name(&tz->device, "thermal_zone%d", tz->id);
result = device_register(&tz->device); result = device_register(&tz->device);
if (result) if (result)
goto release_device; goto release_device;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment