From mboxrd@z Thu Jan 1 00:00:00 1970 From: Miquel Raynal Date: Mon, 3 Sep 2018 08:47:39 +0200 Subject: [U-Boot] [PATCH v7 01/13] lib: strto: parse all lowercase metric prefixes in ustrtoul[l] In-Reply-To: <60a558fc-8bd2-94b7-0ad7-128e21b7c4e8@denx.de> References: <20180831145741.17350-1-miquel.raynal@bootlin.com> <20180831145741.17350-2-miquel.raynal@bootlin.com> <60a558fc-8bd2-94b7-0ad7-128e21b7c4e8@denx.de> Message-ID: <20180903084739.23c59a0e@xps13> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de Hi Stefan, Stefan Roese wrote on Sat, 1 Sep 2018 10:43:01 +0200: > On 31.08.2018 16:57, Miquel Raynal wrote: > > Both ustrtoul and ustrtoull interpret 1k but not 1m or 1g. Even if the > > SI symbols for Mega and Giga are 'M' and 'G', certain entries of > > eg. mtdparts also use (wrongly) the metric prefix 'm' and 'g'. =20 > > > I do not see how parsing lowercase prefixes could break anything, so = =20 > > parse them like their uppercase counterpart. =20 > > > Signed-off-by: Miquel Raynal =20 > > --- > > lib/strto.c | 4 ++++ > > 1 file changed, 4 insertions(+) =20 > > > diff --git a/lib/strto.c b/lib/strto.c =20 > > index 7f6076909a..84f8d92d57 100644 > > --- a/lib/strto.c > > +++ b/lib/strto.c > > @@ -87,9 +87,11 @@ unsigned long ustrtoul(const char *cp, char **endp, = unsigned int base) > > unsigned long result =3D simple_strtoul(cp, endp, base); > > switch (**endp) { > > case 'G': > > + case 'g': > > result *=3D 1024; > > /* fall through */ > > case 'M': > > + case 'm': > > result *=3D 1024; > > /* fall through */ > > case 'K': > > @@ -110,9 +112,11 @@ unsigned long long ustrtoull(const char *cp, char = **endp, unsigned int base) > > unsigned long long result =3D simple_strtoull(cp, endp, base); > > switch (**endp) { > > case 'G': > > + case 'g': > > result *=3D 1024; > > /* fall through */ > > case 'M': > > + case 'm': =20 >=20 > Wouldn't it be better, to use tolower() on the char and drop all the > upper case checks completely - also for the 'K' case? Sure, I can do that! Thanks, Miqu=C3=A8l