Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-27 Thread Lukas Wunner
On Tue, Mar 27, 2018 at 05:37:18PM -0700, Laura Abbott wrote: > On 03/18/2018 07:23 AM, Lukas Wunner wrote: > > Actually, scratch that. If ngpio is usually smallish, we can just > > allocate reasonably sized space for mask and bits on the stack, > > and fall back to the kcalloc slowpath only if

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-27 Thread Lukas Wunner
On Tue, Mar 27, 2018 at 05:37:18PM -0700, Laura Abbott wrote: > On 03/18/2018 07:23 AM, Lukas Wunner wrote: > > Actually, scratch that. If ngpio is usually smallish, we can just > > allocate reasonably sized space for mask and bits on the stack, > > and fall back to the kcalloc slowpath only if

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-27 Thread Laura Abbott
On 03/18/2018 07:23 AM, Lukas Wunner wrote: On Sat, Mar 17, 2018 at 09:25:09AM +0100, Lukas Wunner wrote: On Mon, Mar 12, 2018 at 04:00:36PM +0100, Rasmus Villemoes wrote: On 2018-03-10 01:10, Laura Abbott wrote: @@ -2887,14 +2909,30 @@ void gpiod_set_array_value_complex(bool raw, bool

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-27 Thread Laura Abbott
On 03/18/2018 07:23 AM, Lukas Wunner wrote: On Sat, Mar 17, 2018 at 09:25:09AM +0100, Lukas Wunner wrote: On Mon, Mar 12, 2018 at 04:00:36PM +0100, Rasmus Villemoes wrote: On 2018-03-10 01:10, Laura Abbott wrote: @@ -2887,14 +2909,30 @@ void gpiod_set_array_value_complex(bool raw, bool

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-19 Thread Andy Shevchenko
On Mon, Mar 19, 2018 at 9:00 AM, Lukas Wunner wrote: > On Sun, Mar 18, 2018 at 09:34:12PM +0100, Rasmus Villemoes wrote: >> On 2018-03-18 15:23, Lukas Wunner wrote: >> > Actually, scratch that. If ngpio is usually smallish, we can just >> > allocate reasonably sized space for

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-19 Thread Andy Shevchenko
On Mon, Mar 19, 2018 at 9:00 AM, Lukas Wunner wrote: > On Sun, Mar 18, 2018 at 09:34:12PM +0100, Rasmus Villemoes wrote: >> On 2018-03-18 15:23, Lukas Wunner wrote: >> > Actually, scratch that. If ngpio is usually smallish, we can just >> > allocate reasonably sized space for mask and bits on

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-19 Thread Lukas Wunner
On Sun, Mar 18, 2018 at 09:34:12PM +0100, Rasmus Villemoes wrote: > On 2018-03-18 15:23, Lukas Wunner wrote: > >>> Other random thoughts: maybe two allocations for each loop iteration is > >>> a bit much. Maybe do a first pass over the array and collect the maximal > >>> chip->ngpio, do the memory

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-19 Thread Lukas Wunner
On Sun, Mar 18, 2018 at 09:34:12PM +0100, Rasmus Villemoes wrote: > On 2018-03-18 15:23, Lukas Wunner wrote: > >>> Other random thoughts: maybe two allocations for each loop iteration is > >>> a bit much. Maybe do a first pass over the array and collect the maximal > >>> chip->ngpio, do the memory

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-18 Thread Rasmus Villemoes
On 2018-03-18 15:23, Lukas Wunner wrote: >>> >>> Other random thoughts: maybe two allocations for each loop iteration is >>> a bit much. Maybe do a first pass over the array and collect the maximal >>> chip->ngpio, do the memory allocation and freeing outside the loop (then >>> you'd of course

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-18 Thread Rasmus Villemoes
On 2018-03-18 15:23, Lukas Wunner wrote: >>> >>> Other random thoughts: maybe two allocations for each loop iteration is >>> a bit much. Maybe do a first pass over the array and collect the maximal >>> chip->ngpio, do the memory allocation and freeing outside the loop (then >>> you'd of course

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-18 Thread Lukas Wunner
On Sat, Mar 17, 2018 at 09:25:09AM +0100, Lukas Wunner wrote: > On Mon, Mar 12, 2018 at 04:00:36PM +0100, Rasmus Villemoes wrote: > > On 2018-03-10 01:10, Laura Abbott wrote: > > > @@ -2887,14 +2909,30 @@ void gpiod_set_array_value_complex(bool raw, bool > > > can_sleep, > > > > > > while (i

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-18 Thread Lukas Wunner
On Sat, Mar 17, 2018 at 09:25:09AM +0100, Lukas Wunner wrote: > On Mon, Mar 12, 2018 at 04:00:36PM +0100, Rasmus Villemoes wrote: > > On 2018-03-10 01:10, Laura Abbott wrote: > > > @@ -2887,14 +2909,30 @@ void gpiod_set_array_value_complex(bool raw, bool > > > can_sleep, > > > > > > while (i

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-17 Thread Lukas Wunner
On Mon, Mar 12, 2018 at 04:00:36PM +0100, Rasmus Villemoes wrote: > On 2018-03-10 01:10, Laura Abbott wrote: > > @@ -2887,14 +2909,30 @@ void gpiod_set_array_value_complex(bool raw, bool > > can_sleep, > > > > while (i < array_size) { > > struct gpio_chip *chip =

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-17 Thread Lukas Wunner
On Mon, Mar 12, 2018 at 04:00:36PM +0100, Rasmus Villemoes wrote: > On 2018-03-10 01:10, Laura Abbott wrote: > > @@ -2887,14 +2909,30 @@ void gpiod_set_array_value_complex(bool raw, bool > > can_sleep, > > > > while (i < array_size) { > > struct gpio_chip *chip =

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-13 Thread Rasmus Villemoes
On 2018-03-13 00:40, Laura Abbott wrote: > On 03/12/2018 08:00 AM, Rasmus Villemoes wrote: >> >> Hm, it seems you're now only clearing the first word of mask, not the >> entire allocation. Why not just use kcalloc() instead of kmalloc_array >> to have it automatically cleared? > > Bleh, I didn't

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-13 Thread Rasmus Villemoes
On 2018-03-13 00:40, Laura Abbott wrote: > On 03/12/2018 08:00 AM, Rasmus Villemoes wrote: >> >> Hm, it seems you're now only clearing the first word of mask, not the >> entire allocation. Why not just use kcalloc() instead of kmalloc_array >> to have it automatically cleared? > > Bleh, I didn't

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-12 Thread Laura Abbott
On 03/12/2018 08:00 AM, Rasmus Villemoes wrote: On 2018-03-10 01:10, Laura Abbott wrote: /* collect all inputs belonging to the same chip */ first = i; - memset(mask, 0, sizeof(mask)); + memset(mask, 0, sizeof(*mask)); see below @@

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-12 Thread Laura Abbott
On 03/12/2018 08:00 AM, Rasmus Villemoes wrote: On 2018-03-10 01:10, Laura Abbott wrote: /* collect all inputs belonging to the same chip */ first = i; - memset(mask, 0, sizeof(mask)); + memset(mask, 0, sizeof(*mask)); see below @@

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-12 Thread Rasmus Villemoes
On 2018-03-10 01:10, Laura Abbott wrote: > /* collect all inputs belonging to the same chip */ > first = i; > - memset(mask, 0, sizeof(mask)); > + memset(mask, 0, sizeof(*mask)); see below > @@ -2887,14 +2909,30 @@ void

Re: [PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-12 Thread Rasmus Villemoes
On 2018-03-10 01:10, Laura Abbott wrote: > /* collect all inputs belonging to the same chip */ > first = i; > - memset(mask, 0, sizeof(mask)); > + memset(mask, 0, sizeof(*mask)); see below > @@ -2887,14 +2909,30 @@ void

[PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-09 Thread Laura Abbott
The new challenge is to remove VLAs from the kernel (see https://lkml.org/lkml/2018/3/7/621) This patch replaces several VLAs with an appropriate call to kmalloc_array. Signed-off-by: Laura Abbott --- drivers/gpio/gpiolib.c | 55

[PATCH 1/4] gpio: Remove VLA from gpiolib

2018-03-09 Thread Laura Abbott
The new challenge is to remove VLAs from the kernel (see https://lkml.org/lkml/2018/3/7/621) This patch replaces several VLAs with an appropriate call to kmalloc_array. Signed-off-by: Laura Abbott --- drivers/gpio/gpiolib.c | 55 +++--- 1 file