Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

Signed-off-by: Riyan Dhiman <riyandhiman14@gmail.com>
Link: https://lore.kernel.org/r/20240901182244.45543-1-riyandhiman14@gmail.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Riyan Dhiman and committed by
Ulf Hansson
6f25e5de d2253bfa

+3 -3
+3 -3
drivers/mmc/core/block.c
··· 353 353 const char *buf, size_t count) 354 354 { 355 355 int ret; 356 - char *end; 357 356 struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev)); 358 - unsigned long set = simple_strtoul(buf, &end, 0); 359 - if (end == buf) { 357 + unsigned long set; 358 + 359 + if (kstrtoul(buf, 0, &set)) { 360 360 ret = -EINVAL; 361 361 goto out; 362 362 }