From: Zhihao Cheng <chengzhihao1@huawei.com>
To: haoyu.lu <hechushiguitu666@gmail.com>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>
Cc: <linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] ubi: build: replace simple_strtoul with kstrtouint in open_mtd_device()
Date: Thu, 7 May 2026 15:40:21 +0800 [thread overview]
Message-ID: <8a9964a1-bfd8-21c1-10d9-94989cc3a340@huawei.com> (raw)
In-Reply-To: <20260507032308.16485-1-hechushiguitu666@gmail.com>
在 2026/5/7 11:23, haoyu.lu 写道:
> 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(-)
>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
> 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;
> }
>
prev parent reply other threads:[~2026-05-07 7:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-07 3:23 haoyu.lu
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 ` Zhihao Cheng [this message]
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=8a9964a1-bfd8-21c1-10d9-94989cc3a340@huawei.com \
--to=chengzhihao1@huawei.com \
--cc=hechushiguitu666@gmail.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
all inboxes | Powered by JetHome®