Re: [PATCH] kstrtox: reuse functions from ctype.h

From: Michal Nazarewicz
Date: Thu Apr 14 2011 - 10:30:28 EST

On Thu, 14 Apr 2011 16:06:34 +0200, Alexey Dobriyan <adobriyan@xxxxxxxxx> wrote:

On Thu, Apr 14, 2011 at 4:34 PM, Michal Nazarewicz <mina86@xxxxxxxxxx> wrote:
kstrto*() family of functions uses open coded test
for a hexadecimal digit and

Yes, so?

So it's better to avoid open-coded code without a reason if there is
already function for what one tries to do.

own implementation of tolower() function.

It's special cased for this very usage, because the rest of ASCII is
of no concern.
It doesn't claim tolower() semantics.

Either way, the question is do we care about this optimisation so much
as to use it and somehow duplicate code which already is in ctype.h.

I'm not saying we don't. I'm asking whether we want to.

@@ -47,8 +42,8 @@ static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)

if ('0' <= *s && *s <= '9')
val = *s - '0';
- else if ('a' <= _tolower(*s) && _tolower(*s) <= 'f')
- val = _tolower(*s) - 'a' + 10;
+ else if (isxdigit(*s))

[0-9] are isxdigit() as well, so the code sort of logically duplicate.

Yes, so? ;)

I think isxdigit(*s) looks nicer than â'a' <= _tolower(*s) &&
_tolower(*s) <= 'f'â.

+ val = tolower(*s) - 'a' + 10;

Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +-----<email/xmpp: mnazarewicz@xxxxxxxxxx>-----ooO--(_)--Ooo--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at