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

firmware_loader: Replace simple_strtol() with kstrtoint()

Replace deprecated simple_strtol() calls with kstrtoint() in
timeout_store() and firmware_loading_store() functions to
improve input validation and error handling. The simple_strtol()
function does not provide proper error checking for invalid input,
while kstrtoint() returns an error for malformed strings.

This change adds proper validation for user input from sysfs attributes,
returning -EINVAL for invalid numeric strings instead of silently accepting
potentially malformed input. The behavior for valid numeric input remains
unchanged.

The simple_strtol() function is deprecated in favor of kstrtoint() family
functions which provide better error handling and are recommended for new
code and replacements.

Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
Link: https://patch.msgid.link/20250925063812.2269501-1-kaushlendra.kumar@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Kaushlendra Kumar and committed by
Greg Kroah-Hartman
b811e8a0 fe6193a3

+8 -2
+8 -2
drivers/base/firmware_loader/sysfs.c
··· 47 47 static ssize_t timeout_store(const struct class *class, const struct class_attribute *attr, 48 48 const char *buf, size_t count) 49 49 { 50 - int tmp_loading_timeout = simple_strtol(buf, NULL, 10); 50 + int tmp_loading_timeout; 51 + 52 + if (kstrtoint(buf, 10, &tmp_loading_timeout)) 53 + return -EINVAL; 51 54 52 55 if (tmp_loading_timeout < 0) 53 56 tmp_loading_timeout = 0; ··· 160 157 struct fw_sysfs *fw_sysfs = to_fw_sysfs(dev); 161 158 struct fw_priv *fw_priv; 162 159 ssize_t written = count; 163 - int loading = simple_strtol(buf, NULL, 10); 160 + int loading; 161 + 162 + if (kstrtoint(buf, 10, &loading)) 163 + return -EINVAL; 164 164 165 165 mutex_lock(&fw_lock); 166 166 fw_priv = fw_sysfs->fw_priv;