Commit adc8749b authored by Yue Hu's avatar Yue Hu Committed by Zhang Rui

thermal/drivers/core: Use put_device() if device_register() fails

Never directly free @dev after calling device_register(), even if it
returned an error! Always use put_device() to give up the reference
initialized. Clean up the rollback block also.
Signed-off-by: default avatarYue Hu <huyue2@yulong.com>
Signed-off-by: default avatarZhang Rui <rui.zhang@intel.com>
parent 8c7aa184
...@@ -985,7 +985,7 @@ __thermal_cooling_device_register(struct device_node *np, ...@@ -985,7 +985,7 @@ __thermal_cooling_device_register(struct device_node *np,
result = device_register(&cdev->device); result = device_register(&cdev->device);
if (result) { if (result) {
ida_simple_remove(&thermal_cdev_ida, cdev->id); ida_simple_remove(&thermal_cdev_ida, cdev->id);
kfree(cdev); put_device(&cdev->device);
return ERR_PTR(result); return ERR_PTR(result);
} }
...@@ -1240,6 +1240,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, ...@@ -1240,6 +1240,7 @@ thermal_zone_device_register(const char *type, int trips, int mask,
struct thermal_zone_device *tz; struct thermal_zone_device *tz;
enum thermal_trip_type trip_type; enum thermal_trip_type trip_type;
int trip_temp; int trip_temp;
int id;
int result; int result;
int count; int count;
struct thermal_governor *governor; struct thermal_governor *governor;
...@@ -1266,11 +1267,13 @@ thermal_zone_device_register(const char *type, int trips, int mask, ...@@ -1266,11 +1267,13 @@ thermal_zone_device_register(const char *type, int trips, int mask,
INIT_LIST_HEAD(&tz->thermal_instances); INIT_LIST_HEAD(&tz->thermal_instances);
ida_init(&tz->ida); ida_init(&tz->ida);
mutex_init(&tz->lock); mutex_init(&tz->lock);
result = ida_simple_get(&thermal_tz_ida, 0, 0, GFP_KERNEL); id = ida_simple_get(&thermal_tz_ida, 0, 0, GFP_KERNEL);
if (result < 0) if (id < 0) {
result = id;
goto free_tz; goto free_tz;
}
tz->id = result; tz->id = id;
strlcpy(tz->type, type, sizeof(tz->type)); strlcpy(tz->type, type, sizeof(tz->type));
tz->ops = ops; tz->ops = ops;
tz->tzp = tzp; tz->tzp = tzp;
...@@ -1292,7 +1295,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, ...@@ -1292,7 +1295,7 @@ thermal_zone_device_register(const char *type, int trips, int mask,
dev_set_name(&tz->device, "thermal_zone%d", tz->id); 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 remove_device_groups; goto release_device;
for (count = 0; count < trips; count++) { for (count = 0; count < trips; count++) {
if (tz->ops->get_trip_type(tz, count, &trip_type)) if (tz->ops->get_trip_type(tz, count, &trip_type))
...@@ -1343,14 +1346,12 @@ thermal_zone_device_register(const char *type, int trips, int mask, ...@@ -1343,14 +1346,12 @@ thermal_zone_device_register(const char *type, int trips, int mask,
return tz; return tz;
unregister: unregister:
ida_simple_remove(&thermal_tz_ida, tz->id); device_del(&tz->device);
device_unregister(&tz->device); release_device:
return ERR_PTR(result); put_device(&tz->device);
tz = NULL;
remove_device_groups:
thermal_zone_destroy_device_groups(tz);
remove_id: remove_id:
ida_simple_remove(&thermal_tz_ida, tz->id); ida_simple_remove(&thermal_tz_ida, id);
free_tz: free_tz:
kfree(tz); kfree(tz);
return ERR_PTR(result); return ERR_PTR(result);
......
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