From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout07.his.huawei.com (canpmsgout07.his.huawei.com [113.46.200.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5BE02EC57C for ; Thu, 7 May 2026 07:40:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.222 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778139629; cv=none; b=XnfEYKHhTMteVpLOX7RqxhNEfTOLhJNb8+sdix1U1WYuVPn8TU5j+t7GMdEJNf1WDkXVSZPpsgGy9xPRPFRu3zJbiqAI3Y7mwjjTo6yR4JXx8wmpSPoew+/L3P/wrJfaWOS7CLWwwnKxdvQXZlklsJh1fOOmJZSA10GD18uA+sI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778139629; c=relaxed/simple; bh=uuYu+Lw0ZoyqF8I3sgVgiLj6S0dDA7cSslN/b545kB8=; h=Subject:To:CC:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=ShkKhHFgecpSfGHG+uk3u8+D+AfhDIlLH9VhcUIZW8VWL/wKFj1rM4qixlq+R5P0jfksZKPSC6eYh1cihKAiwG2uFL1Suv5h+Ip1mA4NBQEGBqH/TqZ2k5+pzheXuLqNgUqxq8rybJxsxULDnZWXnHwHmEO29iU8EMyZw3bRxs8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=f763sY9W; arc=none smtp.client-ip=113.46.200.222 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="f763sY9W" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=3Vr5xohz+n+kz/ruxUAj62J4VpxUnciK4Pdu96D8bMI=; b=f763sY9WjcwGVXaYIxnPHBXMhUz3KChCFC7BFK30j3Cu7JHsV8VseGpssmm4GHeGAWFlfAml+ KB2uOGrETHLA7j6YImAEK3mZCFcNJ/fSPpx/E+54mehwo6+4Ru1yWFUKJGZ9HbE7WxynO4Jt9Yv Bqae256SK35/MVm9asTW7K0= Received: from mail.maildlp.com (unknown [172.19.163.15]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4gB3r15qrczLlSv; Thu, 7 May 2026 15:32:49 +0800 (CST) Received: from kwepemk500005.china.huawei.com (unknown [7.202.194.90]) by mail.maildlp.com (Postfix) with ESMTPS id B805040539; Thu, 7 May 2026 15:40:22 +0800 (CST) Received: from [10.174.178.46] (10.174.178.46) by kwepemk500005.china.huawei.com (7.202.194.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 7 May 2026 15:40:22 +0800 Subject: Re: [PATCH 1/2] ubi: build: replace simple_strtoul with kstrtouint in open_mtd_device() To: haoyu.lu , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra CC: , References: <20260507032308.16485-1-hechushiguitu666@gmail.com> From: Zhihao Cheng Message-ID: <8a9964a1-bfd8-21c1-10d9-94989cc3a340@huawei.com> Date: Thu, 7 May 2026 15:40:21 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20260507032308.16485-1-hechushiguitu666@gmail.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To kwepemk500005.china.huawei.com (7.202.194.90) ÔÚ 2026/5/7 11:23, haoyu.lu дµÀ: > From: Haoyu Lu > > 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 > --- > drivers/mtd/ubi/build.c | 15 +++++---------- > 1 file changed, 5 insertions(+), 10 deletions(-) > Reviewed-by: Zhihao Cheng > 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; > } >