From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756351Ab1GRKkT (ORCPT ); Mon, 18 Jul 2011 06:40:19 -0400 Received: from mga14.intel.com ([143.182.124.37]:24624 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753330Ab1GRKkR convert rfc822-to-8bit (ORCPT ); Mon, 18 Jul 2011 06:40:17 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.67,221,1309762800"; d="scan'208";a="28390530" Subject: Re: [PATCH 2/2] lib: call native hex_to_bin() inside _kstrtoull() From: Andy Shevchenko To: Alexey Dobriyan Cc: linux-kernel@vger.kernel.org, Andrew Morton In-Reply-To: References: <5e634c6aaeea13b4a1a541fad0b776180ccfd80b.1310977380.git.andriy.shevchenko@linux.intel.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Organization: Intel Finland Oy Date: Mon, 18 Jul 2011 13:39:49 +0300 Message-ID: <1310985589.3903.4.camel@smile> Mime-Version: 1.0 X-Mailer: Evolution 2.32.3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2011-07-18 at 13:31 +0300, Alexey Dobriyan wrote: > On Mon, Jul 18, 2011 at 11:23 AM, Andy Shevchenko > 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 Intel Finland Oy