[PATCH] s390/time: Replace simple_strtoul with kstrtouint in sysfs online_store

Thorsten Blum posted 1 patch 1 month ago
arch/s390/kernel/time.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] s390/time: Replace simple_strtoul with kstrtouint in sysfs online_store
Posted by Thorsten Blum 1 month ago
Replace simple_strtoul() with the recommended kstrtouint() for parsing
the input buffer. Unlike simple_strtoul(), which returns an unsigned
long, kstrtouint() converts the string directly to an unsigned integer
and avoids implicit casting.

Check the return value of kstrtouint() and reject invalid values. This
adds error handling while preserving behavior for existing values, and
removes use of the deprecated simple_strtoul() helper. The current code
silently sets 'value = 0' if parsing fails, instead of returning
-EINVAL.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/s390/kernel/time.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c
index bd0df61d1907..8439516dc4c4 100644
--- a/arch/s390/kernel/time.c
+++ b/arch/s390/kernel/time.c
@@ -787,7 +787,8 @@ static ssize_t online_store(struct device *dev,
 {
 	unsigned int value;
 
-	value = simple_strtoul(buf, NULL, 0);
+	if (kstrtouint(buf, 0, &value))
+		return -EINVAL;
 	if (value != 0 && value != 1)
 		return -EINVAL;
 	if (!test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags))
-- 
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4