* [PATCH 1/2] mtd: mtdoops: replace simple_strtoul with kstrtouint
@ 2026-04-10 13:37 Haoyu Lu
2026-04-10 13:37 ` [PATCH 2/2] mtd: mtdsuper: " Haoyu Lu
2026-04-27 13:13 ` [PATCH 1/2] mtd: mtdoops: " Miquel Raynal
0 siblings, 2 replies; 3+ messages in thread
From: Haoyu Lu @ 2026-04-10 13:37 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra
Cc: linux-mtd, linux-kernel, Haoyu Lu
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>
---
drivers/mtd/mtdoops.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index b88083751a0c..39df7ce8f55f 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -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)
--
2.53.0.windows.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/2] mtd: mtdsuper: replace simple_strtoul with kstrtouint
2026-04-10 13:37 [PATCH 1/2] mtd: mtdoops: replace simple_strtoul with kstrtouint Haoyu Lu
@ 2026-04-10 13:37 ` Haoyu Lu
2026-04-27 13:13 ` [PATCH 1/2] mtd: mtdoops: " Miquel Raynal
1 sibling, 0 replies; 3+ messages in thread
From: Haoyu Lu @ 2026-04-10 13:37 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra
Cc: linux-mtd, linux-kernel, Haoyu Lu
Modernize string-to-number conversion in mtdsuper.c by replacing
simple_strtoul with kstrtouint. This change provides proper type safety
for MTD device numbers which are non-negative integers.
Using kstrtouint avoids unsigned long to int conversion and is more
appropriate for device indices. The debug output format specifier is
updated to %u for unsigned int.
Signed-off-by: Haoyu Lu <hechushiguitu666@gmail.com>
---
drivers/mtd/mtdsuper.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/mtd/mtdsuper.c b/drivers/mtd/mtdsuper.c
index b7e3763c47f0..c709ff7aa6b5 100644
--- a/drivers/mtd/mtdsuper.c
+++ b/drivers/mtd/mtdsuper.c
@@ -132,12 +132,12 @@ int get_tree_mtd(struct fs_context *fc,
} else if (isdigit(fc->source[3])) {
/* mount by MTD device number name */
- char *endptr;
+ unsigned int mtdnr_val;
- mtdnr = simple_strtoul(fc->source + 3, &endptr, 0);
- if (!*endptr) {
+ if (kstrtouint(fc->source + 3, 0, &mtdnr_val) == 0) {
+ mtdnr = mtdnr_val;
/* It was a valid number */
- pr_debug("MTDSB: mtd%%d, mtdnr %d\n", mtdnr);
+ pr_debug("MTDSB: mtd%%d, mtdnr %u\n", mtdnr_val);
return mtd_get_sb_by_nr(fc, mtdnr, fill_super);
}
}
--
2.53.0.windows.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH 1/2] mtd: mtdoops: replace simple_strtoul with kstrtouint
2026-04-10 13:37 [PATCH 1/2] mtd: mtdoops: replace simple_strtoul with kstrtouint Haoyu Lu
2026-04-10 13:37 ` [PATCH 2/2] mtd: mtdsuper: " Haoyu Lu
@ 2026-04-27 13:13 ` Miquel Raynal
1 sibling, 0 replies; 3+ messages in thread
From: Miquel Raynal @ 2026-04-27 13:13 UTC (permalink / raw)
To: Richard Weinberger, Vignesh Raghavendra, Haoyu Lu; +Cc: linux-mtd, linux-kernel
On Fri, 10 Apr 2026 21:37:34 +0800, Haoyu Lu wrote:
> 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.
>
> [...]
Applied to mtd/next, thanks!
[1/2] mtd: mtdoops: replace simple_strtoul with kstrtouint
commit: 6b07cdff176bc5f8fef459b85a7e2ea09e68543f
[2/2] mtd: mtdsuper: replace simple_strtoul with kstrtouint
commit: a92a9a49288d1aad67bd12457c80a1e3f463d85b
Patche(s) should be available on mtd/linux.git and will be
part of the next PR (provided that no robot complains by then).
Kind regards,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-27 13:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-10 13:37 [PATCH 1/2] mtd: mtdoops: replace simple_strtoul with kstrtouint Haoyu Lu
2026-04-10 13:37 ` [PATCH 2/2] mtd: mtdsuper: " Haoyu Lu
2026-04-27 13:13 ` [PATCH 1/2] mtd: mtdoops: " Miquel Raynal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox