Re: [PATCH] mmc: core: convert simple_stroul to kstroul

From: Andy Shevchenko
Date: Mon Sep 16 2024 - 11:19:29 EST


On Tue, Sep 03, 2024 at 02:37:25PM +0200, Ulf Hansson wrote:
> On Sun, 1 Sept 2024 at 20:22, Riyan Dhiman <riyandhiman14@xxxxxxxxx> wrote:
> >
> > simple_strtoul() is obsolete and lacks proper error handling, making it
> > unsafe for converting strings to unsigned long values. Replace it with
> > kstrtoul(), which provides robust error checking and better safety.
> >
> > This change improves the reliability of the string-to-integer conversion
> > and aligns with current kernel coding standards. Error handling is added
> > to catch conversion failures, returning -EINVAL when input is invalid.
> >
> > Issue reported by checkpatch:
> > - WARNING: simple_strtoul is obsolete, use kstrtoul instead

In rare cases this is a false positive, here seems to be okay.

...

> > + if (kstrtoul(buf, 0, &set)) {
> > ret = -EINVAL;
> > goto out;
> > }

Now you shadow the error code of kstrtox(), this has to be as simple as

ret = kstrtoul(buf, 0, &set);
if (ret)
goto out;

--
With Best Regards,
Andy Shevchenko