From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: linux-kernel@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 2/2] lib: call native hex_to_bin() inside _kstrtoull()
Date: Mon, 18 Jul 2011 13:39:49 +0300 [thread overview]
Message-ID: <1310985589.3903.4.camel@smile> (raw)
In-Reply-To: <CACVxJT-0=cpieN52g2LZ1W+PPmpL-kR9nHCk53bBSR=Js1cbRA@mail.gmail.com>
On Mon, 2011-07-18 at 13:31 +0300, Alexey Dobriyan wrote:
> On Mon, Jul 18, 2011 at 11:23 AM, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > --- 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. unlikely() and s++ move don't have anything to do with changes
That's true. I remove those changes.
> 2. I don't understand desire to use some half-thought out API,
> in fact, restricting to radix 16 is arbitrary.
> Without such restriction hex_to_bin doesn't make sense.
I doubt I get it. hex_to_bin validates its input indirectly. The
behaviour of your code (without changes mentioned in 1.) is the same.
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
next prev parent reply other threads:[~2011-07-18 10:40 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 ` [PATCH 2/2] lib: call native hex_to_bin() inside _kstrtoull() Andy Shevchenko
2011-07-18 10:31 ` Alexey Dobriyan
2011-07-18 10:39 ` Andy Shevchenko [this message]
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=1310985589.3903.4.camel@smile \
--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