Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMuHMdX878Vun9oCrECA+uW-ErEgzRx8Gp2wLkoLdKXR0nNKAw@mail.gmail.com>
Date: Fri, 18 May 2018 23:05:17 +0200
From: Geert Uytterhoeven <geert@...ux-m68k.org>
To: Andy Shevchenko <andy.shevchenko@...il.com>
Cc: Laura Abbott <labbott@...hat.com>, Linus Walleij <linus.walleij@...aro.org>, 
	Kees Cook <keescook@...omium.org>, Lukas Wunner <lukas@...ner.de>, 
	Rasmus Villemoes <linux@...musvillemoes.dk>, 
	"open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>, 
	Linux Kernel Mailing List <linux-kernel@...r.kernel.org>, kernel-hardening@...ts.openwall.com, 
	Phil Reid <preid@...ctromag.com.au>
Subject: Re: [PATCHv8] gpio: Remove VLA from gpiolib

Hi Andy,

On Fri, May 18, 2018 at 10:07 PM, Andy Shevchenko
<andy.shevchenko@...il.com> wrote:
> On Fri, May 18, 2018 at 8:53 PM, Laura Abbott <labbott@...hat.com> wrote:
>> The new challenge is to remove VLAs from the kernel
>> (see https://lkml.org/lkml/2018/3/7/621) to eventually
>> turn on -Wvla.
>>
>> Using a kmalloc array is the easy way to fix this but kmalloc is still
>> more expensive than stack allocation. Introduce a fast path with a
>> fixed size stack array to cover most chip with gpios below some fixed
>> amount. The slow path dynamically allocates an array to cover those
>> chips with a large number of gpios.
>
>> +               unsigned long fastpath[2 * BITS_TO_LONGS(FASTPATH_NGPIO)];
>> +               unsigned long *mask, *bits;
>>                 int first, j, ret;
>>
>> +               if (likely(chip->ngpio <= FASTPATH_NGPIO)) {
>> +                       mask = fastpath;
>> +               } else {
>> +                       mask = kmalloc_array(2 * BITS_TO_LONGS(chip->ngpio),
>> +                                          sizeof(*mask),
>> +                                          can_sleep ? GFP_KERNEL : GFP_ATOMIC);
>> +                       if (!mask)
>> +                               return -ENOMEM;
>> +               }
>> +
>> +               bits = mask + BITS_TO_LONGS(chip->ngpio);
>> +               memset(mask, 0, BITS_TO_LONGS(chip->ngpio) * sizeof(*mask));
>
> Wouldn't be better
>
> bitmap_zero(mask, chip->ngpio);
>
> ?

chip->ngpio is never const, so bitmap_zero() would always fall back to
plain memset().

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.