public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] firmware_loader: Replace simple_strtol() with kstrtoint()
@ 2024-04-26 20:25 Haoyang Liu
  2024-04-29 20:50 ` Russ Weight
  2024-05-04 18:22 ` Andy Shevchenko
  0 siblings, 2 replies; 5+ messages in thread
From: Haoyang Liu @ 2024-04-26 20:25 UTC (permalink / raw)
  To: Luis Chamberlain, Russ Weight, Greg Kroah-Hartman,
	Rafael J. Wysocki
  Cc: hust-os-kernel-patches, Haoyang Liu, Dan Carpenter, linux-kernel

simple_strtol() is obsolete, use kstrtoint() instead.

Signed-off-by: Haoyang Liu <tttturtleruss@hust.edu.cn>
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/base/firmware_loader/sysfs.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/base/firmware_loader/sysfs.c b/drivers/base/firmware_loader/sysfs.c
index c9c93b47d9a5..4de1cb243bee 100644
--- a/drivers/base/firmware_loader/sysfs.c
+++ b/drivers/base/firmware_loader/sysfs.c
@@ -47,8 +47,12 @@ static ssize_t timeout_show(const struct class *class, const struct class_attrib
 static ssize_t timeout_store(const struct class *class, const struct class_attribute *attr,
 			     const char *buf, size_t count)
 {
-	int tmp_loading_timeout = simple_strtol(buf, NULL, 10);
+	int tmp_loading_timeout;
+	int res;
 
+	res = kstrtoint(buf, 10, &tmp_loading_timeout);
+	if (res < 0)
+		return res;
 	if (tmp_loading_timeout < 0)
 		tmp_loading_timeout = 0;
 
@@ -157,8 +161,12 @@ static ssize_t firmware_loading_store(struct device *dev,
 	struct fw_sysfs *fw_sysfs = to_fw_sysfs(dev);
 	struct fw_priv *fw_priv;
 	ssize_t written = count;
-	int loading = simple_strtol(buf, NULL, 10);
+	int loading;
+	int res;
 
+	res = kstrtoint(buf, 10, &loading);
+	if (res < 0)
+		return res;
 	mutex_lock(&fw_lock);
 	fw_priv = fw_sysfs->fw_priv;
 	if (fw_state_is_aborted(fw_priv) || fw_state_is_done(fw_priv))
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [PATCH] firmware_loader: Replace simple_strtol() with kstrtoint()
@ 2025-09-25  6:38 Kaushlendra Kumar
  0 siblings, 0 replies; 5+ messages in thread
From: Kaushlendra Kumar @ 2025-09-25  6:38 UTC (permalink / raw)
  To: mcgrof, russ.weight, dakr, gregkh, rafael; +Cc: linux-kernel, Kaushlendra Kumar

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>
---
 drivers/base/firmware_loader/sysfs.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/base/firmware_loader/sysfs.c b/drivers/base/firmware_loader/sysfs.c
index add0b9b75edd..92e91050f96a 100644
--- a/drivers/base/firmware_loader/sysfs.c
+++ b/drivers/base/firmware_loader/sysfs.c
@@ -47,7 +47,10 @@ static ssize_t timeout_show(const struct class *class, const struct class_attrib
 static ssize_t timeout_store(const struct class *class, const struct class_attribute *attr,
 			     const char *buf, size_t count)
 {
-	int tmp_loading_timeout = simple_strtol(buf, NULL, 10);
+	int tmp_loading_timeout;
+
+	if (kstrtoint(buf, 10, &tmp_loading_timeout))
+		return -EINVAL;
 
 	if (tmp_loading_timeout < 0)
 		tmp_loading_timeout = 0;
@@ -157,7 +160,10 @@ static ssize_t firmware_loading_store(struct device *dev,
 	struct fw_sysfs *fw_sysfs = to_fw_sysfs(dev);
 	struct fw_priv *fw_priv;
 	ssize_t written = count;
-	int loading = simple_strtol(buf, NULL, 10);
+	int loading;
+
+	if (kstrtoint(buf, 10, &loading))
+		return -EINVAL;
 
 	mutex_lock(&fw_lock);
 	fw_priv = fw_sysfs->fw_priv;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-09-25  6:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-26 20:25 [PATCH] firmware_loader: Replace simple_strtol() with kstrtoint() Haoyang Liu
2024-04-29 20:50 ` Russ Weight
2024-05-04 18:22 ` Andy Shevchenko
2024-05-05  6:35   ` Greg Kroah-Hartman
  -- strict thread matches above, loose matches on Subject: below --
2025-09-25  6:38 Kaushlendra Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox