mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: linux-kernel@vger.kernel.org
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Alexey Dobriyan <adobriyan@gmail.com>
Subject: [PATCH 2/2] lib: call native hex_to_bin() inside _kstrtoull()
Date: Mon, 18 Jul 2011 11:23:24 +0300	[thread overview]
Message-ID: <5e634c6aaeea13b4a1a541fad0b776180ccfd80b.1310977380.git.andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <e01fb9d779703004bf2f217ec7a2c3e7220610b9.1310977380.git.andriy.shevchenko@linux.intel.com>
In-Reply-To: <e01fb9d779703004bf2f217ec7a2c3e7220610b9.1310977380.git.andriy.shevchenko@linux.intel.com>

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
---
 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


  reply	other threads:[~2011-07-18  8:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-18  8:23 [PATCH 1/2] lib: make TOLOWER macro public Andy Shevchenko
2011-07-18  8:23 ` Andy Shevchenko [this message]
2011-07-18 10:31   ` [PATCH 2/2] lib: call native hex_to_bin() inside _kstrtoull() Alexey Dobriyan
2011-07-18 10:39     ` Andy Shevchenko
2011-07-18 12:57     ` [PATCHv2 1/2] lib: make _tolower() public Andy Shevchenko
2011-07-18 12:57       ` [PATCHv2 2/2] lib: kstrtox: add performance test case Andy Shevchenko
2011-07-18 20:52       ` [PATCHv2 1/2] lib: make _tolower() public Alexey Dobriyan
2011-07-19  7:17         ` [PATCHv2.1] " Andy Shevchenko
2011-07-18 19:05     ` [PATCH 2/2] lib: call native hex_to_bin() inside _kstrtoull() Andy Shevchenko
2011-07-18 10:25 ` [PATCH 1/2] lib: make TOLOWER macro public Alexey Dobriyan
2011-07-18 10:36   ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5e634c6aaeea13b4a1a541fad0b776180ccfd80b.1310977380.git.andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®