The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Akash Sukhavasi <akash.sukhavasi@gmail.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Input: analog: replace deprecated simple_strtoul() with kstrtouint()
Date: Sat, 9 May 2026 10:55:20 +0100	[thread overview]
Message-ID: <20260509105520.61f823a5@pumpkin> (raw)
In-Reply-To: <20260509024048.46132-1-akash.sukhavasi@gmail.com>

On Fri,  8 May 2026 21:40:48 -0500
Akash Sukhavasi <akash.sukhavasi@gmail.com> wrote:

> 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

> 
> Signed-off-by: Akash Sukhavasi <akash.sukhavasi@gmail.com>
> ---
>  drivers/input/joystick/analog.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
> index b6f7bce1c..07ad360f8 100644
> --- a/drivers/input/joystick/analog.c
> +++ b/drivers/input/joystick/analog.c
> @@ -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;


      reply	other threads:[~2026-05-09  9:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-09  2:40 [PATCH] Input: analog: replace deprecated simple_strtoul() with kstrtouint() Akash Sukhavasi
2026-05-09  9:55 ` David Laight [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260509105520.61f823a5@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=akash.sukhavasi@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox