]> www.infradead.org Git - linux.git/commitdiff
misc: tsl2550: replace simple_strtoul to kstrtoul
authorHongbo Li <lihongbo22@huawei.com>
Fri, 30 Aug 2024 08:03:11 +0000 (16:03 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 3 Sep 2024 10:34:31 +0000 (12:34 +0200)
The function simple_strtoul performs no error checking
in scenarios where the input value overflows the intended
output variable.

We can replace the use of the simple_strtoul with the safer
alternatives kstrtoul.

Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
Link: https://lore.kernel.org/r/20240830080311.3545307-1-lihongbo22@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/tsl2550.c

index 2ad4387c98374c2055c1a5ce60a0ee0379018c0b..1a7796ab3fad125971b4369ae82c2e4131ad6176 100644 (file)
@@ -185,10 +185,10 @@ static ssize_t tsl2550_store_power_state(struct device *dev,
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct tsl2550_data *data = i2c_get_clientdata(client);
-       unsigned long val = simple_strtoul(buf, NULL, 10);
+       unsigned long val;
        int ret;
 
-       if (val > 1)
+       if (kstrtoul(buf, 10, &val) || val > 1)
                return -EINVAL;
 
        mutex_lock(&data->update_lock);
@@ -217,10 +217,10 @@ static ssize_t tsl2550_store_operating_mode(struct device *dev,
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct tsl2550_data *data = i2c_get_clientdata(client);
-       unsigned long val = simple_strtoul(buf, NULL, 10);
+       unsigned long val;
        int ret;
 
-       if (val > 1)
+       if (kstrtoul(buf, 10, &val) || val > 1)
                return -EINVAL;
 
        if (data->power_state == 0)