Skip to content

Commit 57a427c

Browse files
tititiou36rafaeljw
authored andcommitted
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: Christophe JAILLET <christophe.jaillet@wanadoo.fr> [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 7ef01f2 commit 57a427c

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

drivers/thermal/thermal_core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ static void thermal_release(struct device *dev)
845845
sizeof("cooling_device") - 1)) {
846846
cdev = to_cooling_device(dev);
847847
thermal_cooling_device_destroy_sysfs(cdev);
848-
kfree(cdev->type);
848+
kfree_const(cdev->type);
849849
ida_free(&thermal_cdev_ida, cdev->id);
850850
kfree(cdev);
851851
}
@@ -917,7 +917,7 @@ __thermal_cooling_device_register(struct device_node *np,
917917
cdev->id = ret;
918918
id = ret;
919919

920-
cdev->type = kstrdup(type ? type : "", GFP_KERNEL);
920+
cdev->type = kstrdup_const(type ? type : "", GFP_KERNEL);
921921
if (!cdev->type) {
922922
ret = -ENOMEM;
923923
goto out_ida_remove;
@@ -970,7 +970,7 @@ __thermal_cooling_device_register(struct device_node *np,
970970
out_cooling_dev:
971971
thermal_cooling_device_destroy_sysfs(cdev);
972972
out_cdev_type:
973-
kfree(cdev->type);
973+
kfree_const(cdev->type);
974974
out_ida_remove:
975975
ida_free(&thermal_cdev_ida, id);
976976
out_kfree_cdev:

include/linux/thermal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct thermal_cooling_device_ops {
103103

104104
struct thermal_cooling_device {
105105
int id;
106-
char *type;
106+
const char *type;
107107
unsigned long max_state;
108108
struct device device;
109109
struct device_node *np;

0 commit comments

Comments
 (0)