Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

misc: tsl2550: replace simple_strtoul to kstrtoul

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>

authored by

Hongbo Li and committed by
Greg Kroah-Hartman
072e18d6 e807c406

+4 -4
+4 -4
drivers/misc/tsl2550.c
··· 185 185 { 186 186 struct i2c_client *client = to_i2c_client(dev); 187 187 struct tsl2550_data *data = i2c_get_clientdata(client); 188 - unsigned long val = simple_strtoul(buf, NULL, 10); 188 + unsigned long val; 189 189 int ret; 190 190 191 - if (val > 1) 191 + if (kstrtoul(buf, 10, &val) || val > 1) 192 192 return -EINVAL; 193 193 194 194 mutex_lock(&data->update_lock); ··· 217 217 { 218 218 struct i2c_client *client = to_i2c_client(dev); 219 219 struct tsl2550_data *data = i2c_get_clientdata(client); 220 - unsigned long val = simple_strtoul(buf, NULL, 10); 220 + unsigned long val; 221 221 int ret; 222 222 223 - if (val > 1) 223 + if (kstrtoul(buf, 10, &val) || val > 1) 224 224 return -EINVAL; 225 225 226 226 if (data->power_state == 0)