Re: [PATCH v1 2/3] gpio: aggregator: Simplify isrange() by using get_option()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Andy,

On Sat, Jul 18, 2020 at 11:26 PM Andy Shevchenko
<andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
> We already have a nice helper called get_option() which can be used
> to validate the input format. Simplify isrange() by using it.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>

Thanks for your patch!

> --- a/drivers/gpio/gpio-aggregator.c
> +++ b/drivers/gpio/gpio-aggregator.c
> @@ -64,30 +64,17 @@ static char *get_arg(char **args)
>
>  static bool isrange(const char *s)
>  {
> -       size_t n;
> +       char **args = (char **)&s;
> +       int dummy;
> +       int res;
>
> -       if (IS_ERR_OR_NULL(s))
> +       if (IS_ERR_OR_NULL(s) || *s == '\0')
>                 return false;
>
> -       while (1) {
> -               n = strspn(s, "0123456789");
> -               if (!n)
> -                       return false;
> -
> -               s += n;
> -
> -               switch (*s++) {
> -               case '\0':
> -                       return true;
> -
> -               case '-':
> -               case ',':
> -                       break;
> -
> -               default:
> -                       return false;
> -               }
> -       }
> +       do {
> +               res = get_option(args, &dummy);
> +       } while (res);
> +       return **args == '\0';
>  }

This change makes isrange() return true for all of the following,
although they are not valid ranges:
    -7
    --7
    7-
    7--9

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux