mmc: core: convert simple_stroul to kstroul
PATCH 1/1 mmc: core: convert simple_stroul to kstroul
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
--- drivers/mmc/core/block.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mmc/core/block.c +3 -3
@@ -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; }
Signature · 1 line
2.46.0
Quoted 5 lines · Riyan Dhiman
simple_strtoul()is obsolete and lacks proper error handling, making it unsafe for converting strings to unsigned long values. Replace it withkstrtoul(), which provides robust error checking and better safety.
Quoted 8 lines
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
-EINVALwhen input is invalid.Issue reported by checkpatch:
- WARNING:simple_strtoulis obsolete, use kstrtoul insteadSigned-off-by Riyan Dhiman <[email protected]>
Applied for next, thanks!
Kind regards
Uffe
Quoted 25 lines
--- drivers/mmc/core/block.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/mmc/core/block.c +3
-4@@ -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
Quoted 6 lines · Ulf Hansson
Quoted 5 lines · Riyan Dhiman
simple_strtoul()is obsolete and lacks proper error handling, making it unsafe for converting strings to unsigned long values. Replace it withkstrtoul(), which provides robust error checking and better safety.
Quoted 6 lines
Quoted 6 lines
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
-EINVALwhen input is invalid.Issue reported by checkpatch:
- WARNING:simple_strtoulis obsolete, use kstrtoul instead
In rare cases this is a false positive, here seems to be okay.
...
Quoted 4 lines
Quoted 4 lines
+ 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;Signature · 2 lines
With Best Regards, Andy Shevchenko