]> git.itanic.dy.fi Git - linux-stable/commitdiff
thermal: core: Use kstrdup_const() during cooling device registration
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Fri, 5 Jan 2024 13:45:11 +0000 (14:45 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 12 Jan 2024 14:38:23 +0000 (15:38 +0100)
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>
drivers/thermal/thermal_core.c
include/linux/thermal.h

index abf4c2390b197449d3eb79e173f342e1870f51ea..dfaa6341694a089d2ff1a1c61ee7e12efdfcdbdd 100644 (file)
@@ -845,7 +845,7 @@ static void thermal_release(struct device *dev)
                            sizeof("cooling_device") - 1)) {
                cdev = to_cooling_device(dev);
                thermal_cooling_device_destroy_sysfs(cdev);
-               kfree(cdev->type);
+               kfree_const(cdev->type);
                ida_free(&thermal_cdev_ida, cdev->id);
                kfree(cdev);
        }
@@ -917,7 +917,7 @@ __thermal_cooling_device_register(struct device_node *np,
        cdev->id = ret;
        id = ret;
 
-       cdev->type = kstrdup(type ? type : "", GFP_KERNEL);
+       cdev->type = kstrdup_const(type ? type : "", GFP_KERNEL);
        if (!cdev->type) {
                ret = -ENOMEM;
                goto out_ida_remove;
@@ -970,7 +970,7 @@ __thermal_cooling_device_register(struct device_node *np,
 out_cooling_dev:
        thermal_cooling_device_destroy_sysfs(cdev);
 out_cdev_type:
-       kfree(cdev->type);
+       kfree_const(cdev->type);
 out_ida_remove:
        ida_free(&thermal_cdev_ida, id);
 out_kfree_cdev:
index 7defea8fa223068bbec5f19fad4f839d2b1d988b..3227335fb4471503190291138e302a2720e9aed5 100644 (file)
@@ -103,7 +103,7 @@ struct thermal_cooling_device_ops {
 
 struct thermal_cooling_device {
        int id;
-       char *type;
+       const char *type;
        unsigned long max_state;
        struct device device;
        struct device_node *np;