[PATCH 2/2] lib: call native hex_to_bin() inside _kstrtoull()

From: Andy Shevchenko
Date: Mon Jul 18 2011 - 04:24:12 EST


Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Alexey Dobriyan <adobriyan@xxxxxxxxx>
---
lib/kstrtox.c | 15 ++++-----------
1 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index 5099755..a26d287 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -39,25 +39,18 @@ static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
acc = 0;
ok = 0;
while (*s) {
- unsigned int val;
+ int val;

- if ('0' <= *s && *s <= '9')
- val = *s - '0';
- else if ('a' <= TOLOWER(*s) && TOLOWER(*s) <= 'f')
- val = TOLOWER(*s) - 'a' + 10;
- else if (*s == '\n' && *(s + 1) == '\0')
+ if (unlikely(*s == '\n' && *(s + 1) == '\0'))
break;
- else
- return -EINVAL;

- if (val >= base)
+ val = hex_to_bin(*s++);
+ if (val >= base || val < 0)
return -EINVAL;
if (acc > div_u64(ULLONG_MAX - val, base))
return -ERANGE;
acc = acc * base + val;
ok = 1;
-
- s++;
}
if (!ok)
return -EINVAL;
--
1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/