Linux block layer
 help / color / mirror / Atom feed
From: Tao Cui <cui.tao@linux.dev>
To: bvanassche@acm.org, axboe@kernel.dk
Cc: cui.tao@linux.dev, hch@lst.de, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, Tao Cui <cuitao@kylinos.cn>
Subject: Re: [PATCH v2 2/3] loop: replace simple_strtol() with kstrtoint()
Date: Mon, 31 Aug 2026 18:07:06 +0800	[thread overview]
Message-ID: <276b50cc-6b92-425f-8f70-25b2fade14c0@linux.dev> (raw)
In-Reply-To: <20260831100305.695116-3-cui.tao@linux.dev>


Hi Bart,

在 2026/8/31 18:03, Tao Cui 写道:
> From: Tao Cui <cuitao@kylinos.cn>
> 
> simple_strtol() is deprecated and swallows errors.  Use kstrtoint()
> in the max_loop setup code; an invalid option keeps the default and
> now says so.
> 
> Only mark max_loop_specified when the option was parsed successfully.
> With simple_strtol() a garbage string yields max_loop = 0, and
> loop_probe()'s "max_loop_specified && max_loop" check short-circuits
> on 0, so legacy autoloading is not capped.  Keeping max_loop at its
> default while still setting max_loop_specified would instead turn the
> default into a hard upper bound for dynamic device creation.  This
> mirrors what max_loop_param_set_int() already does for the module
> parameter.
> 

Thanks for the review!

After sending v1 I noticed a regression in this patch, so I'll follow
up with a v2 of just this one (1/3 and 3/3 are unchanged and keep your
Reviewed-by).

With simple_strtol() a garbage max_loop= string yields max_loop = 0,
and loop_probe()'s "max_loop_specified && max_loop" check
short-circuits on 0, so legacy autoloading was not capped.  In v1 an
invalid string keeps max_loop at its default value while
max_loop_specified is still set to true, which turns the default into
a hard upper bound for dynamic device creation.  The v2 only marks
max_loop_specified when kstrtoint() succeeds, mirroring
max_loop_param_set_int():

 	if (kstrtoint(str, 0, &max_loop))
+	{
 		pr_warn("loop: invalid max_loop, keeping default\n");
+		return 1;
+	}
 #ifdef CONFIG_BLOCK_LEGACY_AUTOLOAD
 		max_loop_specified = true;
 #endif

This was pointed out by an AI-assisted review of v1, so I've left your
Reviewed-by off this one for now.  Could you take another look when
you have a chance?

Thanks,
Tao

> Signed-off-by: Tao Cui <cuitao@kylinos.cn>
> 
> ---
> Changes in v2:
> - move max_loop_specified = true under the success path, pointed out
>   by an AI-assisted review of v1.
> ---
>  drivers/block/loop.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/block/loop.c b/drivers/block/loop.c
> index 68a9cc7aeb13..126f42580632 100644
> --- a/drivers/block/loop.c
> +++ b/drivers/block/loop.c
> @@ -2341,7 +2341,10 @@ module_exit(loop_exit);
>  #ifndef MODULE
>  static int __init max_loop_setup(char *str)
>  {
> -	max_loop = simple_strtol(str, NULL, 0);
> +	if (kstrtoint(str, 0, &max_loop)) {
> +		pr_warn("loop: invalid max_loop, keeping default\n");
> +		return 1;
> +	}
>  #ifdef CONFIG_BLOCK_LEGACY_AUTOLOAD
>  	max_loop_specified = true;
>  #endif


  reply	other threads:[~2026-08-31 10:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 10:03 [PATCH 0/3] loop: three small cleanups Tao Cui
2026-08-31 10:03 ` [PATCH v2 1/3] loop: drop a stale reference to loop_validate_size() Tao Cui
2026-09-02 13:59   ` Christoph Hellwig
2026-08-31 10:03 ` [PATCH v2 2/3] loop: replace simple_strtol() with kstrtoint() Tao Cui
2026-08-31 10:07   ` Tao Cui [this message]
2026-08-31 10:03 ` [PATCH v2 3/3] loop: drop the unused argument of lo_req_flush() Tao Cui
2026-09-02 14:00   ` Christoph Hellwig

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=276b50cc-6b92-425f-8f70-25b2fade14c0@linux.dev \
    --to=cui.tao@linux.dev \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=cuitao@kylinos.cn \
    --cc=hch@lst.de \
    --cc=linux-block@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