From: "haoyu.lu" <hechushiguitu666@gmail.com>
To: Miquel Raynal <miquel.raynal@bootlin.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>
Cc: Zhihao Cheng <chengzhihao1@huawei.com>,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
Haoyu Lu <hechushiguitu666@gmail.com>
Subject: [PATCH 1/2] ubi: build: replace simple_strtoul with kstrtouint in open_mtd_device()
Date: Thu, 7 May 2026 03:23:07 +0000 [thread overview]
Message-ID: <20260507032308.16485-1-hechushiguitu666@gmail.com> (raw)
From: Haoyu Lu <hechushiguitu666@gmail.com>
Replace the deprecated simple_strtoul() with kstrtouint() for parsing
the MTD device number string. kstrtouint() provides stricter validation
and better error handling.
In open_mtd_device(), a string that can be parsed as a pure number is
treated as an MTD device index; otherwise it is treated as a device
name. kstrtouint() returns 0 on success and -EINVAL if the string
contains non-numeric characters, which aligns with this logic and
eliminates the need for manual endp checks.
For compatibility with kstrtouint(), mtd_num is changed from int to
unsigned int, consistent with the existing simple_strtoul ->
kstrtouint conversions in mtdoops.c and mtdsuper.c.
The multi-line comment is simplified to a concise single-line comment
since the logic is self-explanatory with kstrtouint().
Signed-off-by: Haoyu Lu <hechushiguitu666@gmail.com>
---
drivers/mtd/ubi/build.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 674ad87809df..03ef195dc25c 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -1210,21 +1210,16 @@ static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev)
static struct mtd_info * __init open_mtd_device(const char *mtd_dev)
{
struct mtd_info *mtd;
- int mtd_num;
- char *endp;
+ unsigned int mtd_num;
- mtd_num = simple_strtoul(mtd_dev, &endp, 0);
- if (*endp != '\0' || mtd_dev == endp) {
- /*
- * This does not look like an ASCII integer, probably this is
- * MTD device name.
- */
+ if (kstrtouint(mtd_dev, 0, &mtd_num) != 0) {
+ /* Not a plain number, treat as MTD device name */
mtd = get_mtd_device_nm(mtd_dev);
if (PTR_ERR(mtd) == -ENODEV)
- /* Probably this is an MTD character device node path */
mtd = open_mtd_by_chdev(mtd_dev);
- } else
+ } else {
mtd = get_mtd_device(NULL, mtd_num);
+ }
return mtd;
}
--
2.17.1
next reply other threads:[~2026-05-07 3:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-07 3:23 haoyu.lu [this message]
2026-05-07 3:23 ` [PATCH 2/2] ubi: build: replace simple_strtoul with kstrtoul in bytes_str_to_int() haoyu.lu
2026-05-07 7:30 ` Richard Weinberger
2026-05-07 7:45 ` Zhihao Cheng
2026-05-07 7:50 ` Richard Weinberger
2026-05-07 8:25 ` Haoyu Lu
2026-05-07 7:40 ` [PATCH 1/2] ubi: build: replace simple_strtoul with kstrtouint in open_mtd_device() Zhihao Cheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260507032308.16485-1-hechushiguitu666@gmail.com \
--to=hechushiguitu666@gmail.com \
--cc=chengzhihao1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox