Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1174178

Re: [PATCH] lib/bitmap.c: return -EINVAL for grouping errors in __bitmap_parselist

Path csiph.com!aioe.org!news.ecp.fr!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!weretis.net!feeder4.news.weretis.net!feeder1.news.weretis.net!newsfeed.CARNet.hr!news.spin.it!bofh.it!news.nic.it!robomod
From Pan Xinhui <xinhuix.pan@intel.com>
Newsgroups linux.kernel
Subject Re: [PATCH] lib/bitmap.c: return -EINVAL for grouping errors in __bitmap_parselist
Date Tue, 30 Jun 2015 03:40:04 +0200
Message-ID <pGSGM-3PE-33@gated-at.bofh.it> (permalink)
References <pGBZg-4ZO-3@gated-at.bofh.it> <pGHrZ-4pF-27@gated-at.bofh.it>
X-Original-To Yury Norov <yury.norov@gmail.com>
X-Extloop1 1
X-Ironport-Av E=Sophos;i="5.15,374,1432623600"; d="scan'208";a="719975156"
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 105
Organization linux.* mail to news gateway
X-Original-Cc "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>, Andrew Morton <akpm@linux-foundation.org>, Rasmus Villemoes <linux@rasmusvillemoes.dk>, tj@kernel.org, peterz@infradead.org, sudeep.holla@arm.com, mina86@mina86.com, "mnipxh@163.com" <mnipxh@163.com>, Alexey Klimov <klimov.linux@gmail.com>
X-Original-Date Wed, 01 Jul 2015 09:37:05 +0800
X-Original-Message-ID <55934441.9010304@intel.com>
X-Original-References <5592487D.7080006@intel.com> <CAAH8bW-ExkJeAh641Fhg-PxCv7M3aiAP2ZYMuzTzUBJ=O7xSJw@mail.gmail.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref aioe.org linux.kernel:1174178

Show key headers only | View raw


hi, Yury
	thanks for your nice reply.

On 2015年06月29日 21:39, Yury Norov wrote:
>> Sometimes the input from user may cause an unexpected result.
>
> Could you please provide specific example?
>
I wrote some scripts to do some tests about irqs.
echo "1-3," > /proc/irq/<xxx>/smp_affinity_list
this command ends with ',' by mistake.
actually __bitmap_parselist() will report "0-3" for the final result which is wrong.

>>
>> just like __bitmap_parse, we return -EINVAL if there is no avaiable digit in each
>> parsing procedures.
>>
>> Signed-off-by: Pan Xinhui <xinhuix.pan@intel.com>
>
> Hello, Pan.
>
> (Adding Alexey Klimov, Rasmus Villemoes)
>
>> ---
>>    lib/bitmap.c | 7 +++++--
>>    1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/lib/bitmap.c b/lib/bitmap.c
>> index 64c0926..995fca2 100644
>> --- a/lib/bitmap.c
>> +++ b/lib/bitmap.c
>> @@ -504,7 +504,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
>>            int nmaskbits)
>>    {
>>        unsigned a, b;
>> -    int c, old_c, totaldigits;
>> +    int c, old_c, totaldigits, ndigits;
>>        const char __user __force *ubuf = (const char __user __force *)buf;
>>        int exp_digit, in_range;
>>
>> @@ -514,6 +514,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
>>            exp_digit = 1;
>>            in_range = 0;
>>            a = b = 0;
>> +        ndigits = 0;
>>
>>            /* Get the next cpu# or a range of cpu#'s */
>>            while (buflen) {
>> @@ -555,8 +556,10 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
>>                if (!in_range)
>>                    a = b;
>>                exp_digit = 0;
>> -            totaldigits++;
>> +            ndigits++; totaldigits++;
>
> I'm not happy with joining two statements to a single line.
> Maybe sometimes it's OK for loop iterators like
>
>      while (a[i][j]) {
>          i++; j++;
>      }
>
> But here it looks nasty. Anyway, it's minor.
>

thanks for pointing out my mistake about the code style :)

>>            }
>> +        if (ndigits == 0)
>> +            return -EINVAL;
>
> You can avoid in-loop incrementation of ndigits if you'll
> save current totaldigits to ndigits before loop, and check
> ndigits against totaldigits after the loop:
>
>      ndigits = totaldigits;
>      while (...) {
>           ...
>          totaldigits++;
>      }
>
>      if (ndigits == totaldigits)
>          return -EINVAL;
>
> Maybe it's a good point to rework initial __bitmap_parse() similar way...
>

your advice is a good idea, thanks.
I am also thinking if we can rewrite them into one function for common codes.

thanks for your reply again :)

thanks
xinhui

>>            if (!(a <= b))
>>                return -EINVAL;
>>            if (b >= nmaskbits)
>> --
>> 1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH] lib/bitmap.c: return -EINVAL for grouping errors in __bitmap_parselist Pan Xinhui <xinhuix.pan@intel.com> - 2015-06-30 03:40 +0200
  [PATCH V3] lib/bitmap.c: rewrite __bitmap_parse && __bitmap_parselist Pan Xinhui <xinhuix.pan@intel.com> - 2015-06-30 12:10 +0200

csiph-web