Commit 57a427c8 authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Rafael J. Wysocki

thermal: core: Use kstrdup_const() during cooling device registration

Some *thermal_cooling_device_register() calls pass a string literal as
the 'type' parameter, so kstrdup_const() can be used instead of
kstrdup() to avoid a memory allocation in such cases.
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
[ rjw: Subject and changelog edits ]
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 7ef01f22
...@@ -845,7 +845,7 @@ static void thermal_release(struct device *dev) ...@@ -845,7 +845,7 @@ static void thermal_release(struct device *dev)
sizeof("cooling_device") - 1)) { sizeof("cooling_device") - 1)) {
cdev = to_cooling_device(dev); cdev = to_cooling_device(dev);
thermal_cooling_device_destroy_sysfs(cdev); thermal_cooling_device_destroy_sysfs(cdev);
kfree(cdev->type); kfree_const(cdev->type);
ida_free(&thermal_cdev_ida, cdev->id); ida_free(&thermal_cdev_ida, cdev->id);
kfree(cdev); kfree(cdev);
} }
...@@ -917,7 +917,7 @@ __thermal_cooling_device_register(struct device_node *np, ...@@ -917,7 +917,7 @@ __thermal_cooling_device_register(struct device_node *np,
cdev->id = ret; cdev->id = ret;
id = ret; id = ret;
cdev->type = kstrdup(type ? type : "", GFP_KERNEL); cdev->type = kstrdup_const(type ? type : "", GFP_KERNEL);
if (!cdev->type) { if (!cdev->type) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_ida_remove; goto out_ida_remove;
...@@ -970,7 +970,7 @@ __thermal_cooling_device_register(struct device_node *np, ...@@ -970,7 +970,7 @@ __thermal_cooling_device_register(struct device_node *np,
out_cooling_dev: out_cooling_dev:
thermal_cooling_device_destroy_sysfs(cdev); thermal_cooling_device_destroy_sysfs(cdev);
out_cdev_type: out_cdev_type:
kfree(cdev->type); kfree_const(cdev->type);
out_ida_remove: out_ida_remove:
ida_free(&thermal_cdev_ida, id); ida_free(&thermal_cdev_ida, id);
out_kfree_cdev: out_kfree_cdev:
......
...@@ -103,7 +103,7 @@ struct thermal_cooling_device_ops { ...@@ -103,7 +103,7 @@ struct thermal_cooling_device_ops {
struct thermal_cooling_device { struct thermal_cooling_device {
int id; int id;
char *type; const char *type;
unsigned long max_state; unsigned long max_state;
struct device device; struct device device;
struct device_node *np; struct device_node *np;
......
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