lkml.org 
[lkml]   [2018]   [Mar]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCHv3] gpio: Remove VLA from gpiolib
On Wed, Mar 28, 2018 at 9:18 PM, Laura Abbott <labbott@redhat.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.

> + ret = gpiod_set_array_value_complex(false,
> true,
> lh->numdescs,
> lh->descs,
> vals);
> + if (ret)
> + return ret;
> +
> return 0;

Can't we

return gpiod_set_array_value_complex(); ?


> + slowpath = kcalloc(2 * BITS_TO_LONGS(chip->ngpio),
> + sizeof(*slowpath),
> + can_sleep ? GFP_KERNEL : GFP_ATOMIC);


> + if (slowpath)
> + kfree(slowpath);

> + if (slowpath)
> + kfree(slowpath);

Since slowpath is a pointer, conditionals above are redundant.

> + slowpath = kcalloc(2 * BITS_TO_LONGS(chip->ngpio),
> + sizeof(*slowpath),
> + can_sleep ? GFP_KERNEL : GFP_ATOMIC);

> + if (slowpath)
> + kfree(slowpath);

Ditto.

--
With Best Regards,
Andy Shevchenko

\
 
 \ /
  Last update: 2018-03-30 16:34    [W:0.057 / U:3.616 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site