Skip to contentSkip to conversation

s390/time: Replace simple_strtoul with kstrtouint in sysfs online_store

PATCH New Thorsten Blum 1 participant 1 message Jan 8 s390

lore
Share & tools
lore
#0 lore raw

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

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.

---
 arch/s390/kernel/time.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kernel/time.c +2 -1
index bd0df61d1907..8439516dc4c4 100644
@@ -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))
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4