[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <hepk5mxy7zfr534i4mbqbjr3jzkqytbnfz66lelzcewwu5h47h@df7qq7laaypr>
Date: Sun, 6 Apr 2025 10:11:53 -0400
From: Kent Overstreet <kent.overstreet@...ux.dev>
To: Integral <integral@...hlinuxcn.org>
Cc: Kent Overstreet <kent.overstreet@...il.com>,
linux-bcachefs@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] bcachefs: return early for negative values when parsing
BCH_OPT_UINT
On Sun, Apr 06, 2025 at 09:59:30PM +0800, Integral wrote:
> Currently, when a negative integer is passed as an argument, the error
> message incorrectly states "too big" due to the value being cast to an
> unsigned integer:
>
> > bcachefs format --block_size=-1 bcachefs.img
> invalid option: block_size: too big (max 65536)
>
> To resolve this issue, return early for negative values before calling
> bch2_opt_validate().
>
> Signed-off-by: Integral <integral@...hlinuxcn.org>
No new -EINVAL in kernel code :)
> ---
> fs/bcachefs/opts.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c
> index e64777ecf44f..31f90c177c6c 100644
> --- a/fs/bcachefs/opts.c
> +++ b/fs/bcachefs/opts.c
> @@ -360,9 +360,15 @@ int bch2_opt_parse(struct bch_fs *c,
> return -EINVAL;
> }
>
> - ret = opt->flags & OPT_HUMAN_READABLE
> - ? bch2_strtou64_h(val, res)
> - : kstrtou64(val, 10, res);
> + if (*val != '-') {
> + ret = opt->flags & OPT_HUMAN_READABLE
> + ? bch2_strtou64_h(val, res)
> + : kstrtou64(val, 10, res);
> + } else {
> + prt_printf(err, "%s: must be a non-negative number", opt->attr.name);
> + return -EINVAL;
> + }
> +
> if (ret < 0) {
> if (err)
> prt_printf(err, "%s: must be a number",
> --
> 2.49.0
>
Powered by blists - more mailing lists