Skip to contentSkip to conversation

Input: analog: replace deprecated simple_strtoul() with kstrtouint()

PATCH In review Akash Sukhavasi 2 participants 3 messages May 9 – May 14

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: analog: replace deprecated simple_strtoul() with kstrtouint()

The simple_strtoul() function is deprecated because it ignores trailing garbage characters, which can mask typos in input.

Replace it with kstrtouint() in analog_parse_options() to enforce strict input parsing.

Note that this introduces a minor, intended behavior change: while the old code would silently parse a malformed string like "12abc" as 12, the new code will reject it entirely and fall back to the unconfigured state (0xff). This strict parsing is the preferred modern behavior for kernel parameters.

---
 drivers/input/joystick/analog.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/input/joystick/analog.c +5 -3
index b6f7bce1c..07ad360f8 100644
@@ -653,7 +653,7 @@ static struct analog_types analog_types[] = {
 static void analog_parse_options(void)
 {
 	int i, j;
-	char *end;
+	unsigned int parsed_val;
 
 	for (i = 0; i < js_nargs; i++) {
 
@@ -664,8 +664,10 @@ static void analog_parse_options(void)
 			}
 		if (analog_types[j].name) continue;
 
-		analog_options[i] = simple_strtoul(js[i], &end, 0);
-		if (end != js[i]) continue;
+		if (kstrtouint(js[i], 0, &parsed_val) == 0) {
+			analog_options[i] = parsed_val;
+			continue;
+		}
 
 		analog_options[i] = 0xff;
 		if (!strlen(js[i])) continue;
Signature · 1 line
2.54.0
#1 lore raw
Quoted 11 lines · On Fri, 8 May 2026 21:40:48 -0500 Akash Sukhavasi <[email protected]>…

The simple_strtoul() function is deprecated because it ignores trailing garbage characters, which can mask typos in input.

Replace it with kstrtouint() in analog_parse_options() to enforce strict input parsing.

Note that this introduces a minor, intended behavior change: while the old code would silently parse a malformed string like "12abc" as 12, the new code will reject it entirely and fall back to the unconfigured state (0xff). This strict parsing is the preferred modern behavior for kernel parameters.

However that might break existing systems.
So I'm not at all sure it should be done.

David

Quoted 32 lines
---
 drivers/input/joystick/analog.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/input/joystick/analog.c +5 -3
index b6f7bce1c..07ad360f8 100644
@@ -653,7 +653,7 @@ static struct analog_types analog_types[] = {
 static void analog_parse_options(void)
 {
 	int i, j;
-	char *end;
+	unsigned int parsed_val;
 
 	for (i = 0; i < js_nargs; i++) {
 
@@ -664,8 +664,10 @@ static void analog_parse_options(void)
 			}
 		if (analog_types[j].name) continue;
 
-		analog_options[i] = simple_strtoul(js[i], &end, 0);
-		if (end != js[i]) continue;
+		if (kstrtouint(js[i], 0, &parsed_val) == 0) {
+			analog_options[i] = parsed_val;
+			continue;
+		}
 
 		analog_options[i] = 0xff;
 		if (!strlen(js[i])) continue;
#2 lore raw
Quoted 2 lines · David Laight

However that might break existing systems.
So I'm not at all sure it should be done.

Hi David,

You're right. It could introduce regressions for users of analog joysticks passing module parameters via scripts or boot configs.

Additionally, digging through list history: Dmitry reviewed this same call in 2011 [1] and chose to leave it, noting the complex parsing semantics were intentional for this context.

Withdrawing the patch. Thanks for the review.

[1] https://lore.kernel.org/all/[email protected]/

Thanks,
Akash