* [PATCH] mmc: core: convert simple_stroul to kstroul
@ 2024-09-01 18:22 Riyan Dhiman
2024-09-03 12:37 ` Ulf Hansson
0 siblings, 1 reply; 3+ messages in thread
From: Riyan Dhiman @ 2024-09-01 18:22 UTC (permalink / raw)
To: ulf.hansson; +Cc: linux-mmc, linux-kernel, Riyan Dhiman
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
Signed-off-by: Riyan Dhiman <riyandhiman14@gmail.com>
---
drivers/mmc/core/block.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 2c9963248fcb..140d2b3504b3 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -307,10 +307,10 @@ static ssize_t force_ro_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
int ret;
- char *end;
struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
- unsigned long set = simple_strtoul(buf, &end, 0);
- if (end == buf) {
+ unsigned long set;
+
+ if (kstrtoul(buf, 0, &set)) {
ret = -EINVAL;
goto out;
}
--
2.46.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mmc: core: convert simple_stroul to kstroul
2024-09-01 18:22 [PATCH] mmc: core: convert simple_stroul to kstroul Riyan Dhiman
@ 2024-09-03 12:37 ` Ulf Hansson
2024-09-16 15:19 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Ulf Hansson @ 2024-09-03 12:37 UTC (permalink / raw)
To: Riyan Dhiman; +Cc: linux-mmc, linux-kernel
On Sun, 1 Sept 2024 at 20:22, Riyan Dhiman <riyandhiman14@gmail.com> 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
>
> Signed-off-by: Riyan Dhiman <riyandhiman14@gmail.com>
Applied for next, thanks!
Kind regards
Uffe
> ---
> drivers/mmc/core/block.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> index 2c9963248fcb..140d2b3504b3 100644
> --- a/drivers/mmc/core/block.c
> +++ b/drivers/mmc/core/block.c
> @@ -307,10 +307,10 @@ static ssize_t force_ro_store(struct device *dev, struct device_attribute *attr,
> const char *buf, size_t count)
> {
> int ret;
> - char *end;
> struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
> - unsigned long set = simple_strtoul(buf, &end, 0);
> - if (end == buf) {
> + unsigned long set;
> +
> + if (kstrtoul(buf, 0, &set)) {
> ret = -EINVAL;
> goto out;
> }
> --
> 2.46.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mmc: core: convert simple_stroul to kstroul
2024-09-03 12:37 ` Ulf Hansson
@ 2024-09-16 15:19 ` Andy Shevchenko
0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2024-09-16 15:19 UTC (permalink / raw)
To: Ulf Hansson; +Cc: Riyan Dhiman, linux-mmc, linux-kernel
On Tue, Sep 03, 2024 at 02:37:25PM +0200, Ulf Hansson wrote:
> On Sun, 1 Sept 2024 at 20:22, Riyan Dhiman <riyandhiman14@gmail.com> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-16 15:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-01 18:22 [PATCH] mmc: core: convert simple_stroul to kstroul Riyan Dhiman
2024-09-03 12:37 ` Ulf Hansson
2024-09-16 15:19 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox