Commit 4748f968 authored by Yang Yingliang's avatar Yang Yingliang Committed by Rafael J. Wysocki

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: 1dd7128b ("thermal/core: Fix null pointer dereference in thermal_release()")
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent b778b4d7
...@@ -894,10 +894,6 @@ __thermal_cooling_device_register(struct device_node *np, ...@@ -894,10 +894,6 @@ __thermal_cooling_device_register(struct device_node *np,
cdev->id = ret; cdev->id = ret;
id = ret; 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;
...@@ -917,6 +913,11 @@ __thermal_cooling_device_register(struct device_node *np, ...@@ -917,6 +913,11 @@ __thermal_cooling_device_register(struct device_node *np,
goto out_kfree_type; goto out_kfree_type;
thermal_cooling_device_setup_sysfs(cdev); thermal_cooling_device_setup_sysfs(cdev);
ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
if (ret) {
thermal_cooling_device_destroy_sysfs(cdev);
goto out_kfree_type;
}
ret = device_register(&cdev->device); ret = device_register(&cdev->device);
if (ret) if (ret)
goto out_kfree_type; goto out_kfree_type;
...@@ -1250,10 +1251,6 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t ...@@ -1250,10 +1251,6 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
tz->id = id; tz->id = id;
strscpy(tz->type, type, sizeof(tz->type)); strscpy(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;
...@@ -1276,6 +1273,11 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t ...@@ -1276,6 +1273,11 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
/* 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);
result = dev_set_name(&tz->device, "thermal_zone%d", tz->id);
if (result) {
thermal_zone_destroy_device_groups(tz);
goto remove_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