Re: [PATCH -next] sh: intc: replace simple_strtoul to kstrtoul
Geert Uytterhoeven <[email protected]>
| Newsgroups | gmane.linux.ports.sh.devel |
|---|---|
| Message-ID | <CAMuHMdX-rRP3BCcm2mxJKjvSoYKnsLudMuFqArQzzVOQ8fv8aQ@mail.gmail.com> |
Hi Hongbo, On Fri, Aug 30, 2024 at 9:56 AM Hongbo Li <[email protected]> wrote: > The function simple_strtoul performs no error checking > in scenarios where the input value overflows the intended > output variable. > > We can replace the use of the simple_strtoul with the safer > alternatives kstrtoul. For fail case, we also print the extra > message. > > Signed-off-by: Hongbo Li <[email protected]> Thanks for your patch! > --- a/drivers/sh/intc/userimask.c > +++ b/drivers/sh/intc/userimask.c > @@ -33,7 +33,8 @@ store_intc_userimask(struct device *dev, > { > unsigned long level; > > - level = simple_strtoul(buf, NULL, 10); > + if (kstrtoul(buf, 10, &level)) > + return -EINVAL; Please pass the error code returned by kstrtoul() instead of hardcoding -EINVAL. > > /* > * Minimal acceptable IRQ levels are in the 2 - 16 range, but Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] 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