]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mtd: mtdoops: replace simple_strtoul with kstrtouint
authorHaoyu Lu <hechushiguitu666@gmail.com>
Fri, 10 Apr 2026 13:37:34 +0000 (21:37 +0800)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Mon, 27 Apr 2026 13:12:58 +0000 (15:12 +0200)
Replace deprecated simple_strtoul with kstrtouint for better error
handling and type safety. The kstrtouint function provides stricter
validation, automatically rejecting inputs like "123abc" that
simple_strtoul would partially accept.

Using kstrtouint avoids unsigned long to int conversion and is more
appropriate for MTD device indices which are non-negative integers.

Signed-off-by: Haoyu Lu <hechushiguitu666@gmail.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
drivers/mtd/mtdoops.c

index b88083751a0c7a4cce0c1b513ca428898d2040d7..39df7ce8f55f75b07d6d97ed6ecd9951f3d3b3a5 100644 (file)
@@ -403,8 +403,7 @@ static struct mtd_notifier mtdoops_notifier = {
 static int __init mtdoops_init(void)
 {
        struct mtdoops_context *cxt = &oops_cxt;
-       int mtd_index;
-       char *endp;
+       unsigned int mtd_index;
 
        if (strlen(mtddev) == 0) {
                pr_err("mtd device (mtddev=name/number) must be supplied\n");
@@ -421,9 +420,9 @@ static int __init mtdoops_init(void)
 
        /* Setup the MTD device to use */
        cxt->mtd_index = -1;
-       mtd_index = simple_strtoul(mtddev, &endp, 0);
-       if (*endp == '\0')
+       if (kstrtouint(mtddev, 0, &mtd_index) == 0) {
                cxt->mtd_index = mtd_index;
+       }
 
        cxt->oops_buf = vmalloc(record_size);
        if (!cxt->oops_buf)