[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <3f8ee41745ac40e58e0aa535029e8751@AcuMS.aculab.com>
Date: Wed, 20 Dec 2023 08:31:48 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Qu Wenruo' <quwenruo.btrfs@....com>, 'David Disseldorp' <ddiss@...e.de>,
Qu Wenruo <wqu@...e.com>
CC: "linux-btrfs@...r.kernel.org" <linux-btrfs@...r.kernel.org>, Andrew Morton
<akpm@...ux-foundation.org>, Christophe JAILLET
<christophe.jaillet@...adoo.fr>, Andy Shevchenko
<andriy.shevchenko@...ux.intel.com>, "linux-kernel@...r.kernel.org"
<linux-kernel@...r.kernel.org>
Subject: RE: [PATCH 1/2] lib/strtox: introduce kstrtoull_suffix() helper
From: Qu Wenruo
> Sent: 19 December 2023 21:18
...
> > How about:
> > suffix = *endptr;
> > if (!strchr(suffixes, suffix))
> > return -ENIVAL;
> > shift = strcspn("KkMmGgTtPp", suffix)/2 * 10 + 10;
>
> This means the caller has to provide the suffix string in this
> particular order.
No, The strchr() checks that the suffix is one the caller wanted.
The strcspn() is against a fixed list - so the order can be
selected to make the code shorter.
Actually strcspn() isn't the function you need.
There might be a function like strchr() that returns a count
but I can't remember its name and it may not be in kernel.
You might have to write:
shift = 0;
for (const char *sfp = "KkMmGgTtPp"; suffix != *sfp; sfp++, shift++) {
if (!*sfp)
return -EINVAL;
}
shift = shift/2 + 1 * 10;
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists