Re: [PATCH v3 6/8] gpiolib: avoid krealloc() in gpiod_get_array()
From: Linus Walleij
Date: Fri Nov 06 2026 - 09:00:35 EST
On Fri, Nov 6, 2026 at 7:30 AM Dmitry Torokhov
<dmitry.torokhov@xxxxxxxxx> wrote:
> Instead of allocating descs before the loop and reallocating it via
> krealloc() when candidate hardware array matching is detected on the
> first iteration, defer allocation of descs until the first descriptor
> is retrieved.
>
> Factor descriptor allocation and fast-path validation into helper
> functions gpio_descs_alloc() and gpio_descs_check_fastpath(). Inside
> the loop, acquire the descriptor using __free(gpiod_put), allocate
> descs once on the first iteration, check fast-path candidate
> suitability, and transfer descriptor ownership using no_free_ptr().
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
The kernel clearly looks better after this patch than before so:
Reviewed-by: Linus Walleij <linusw@xxxxxxxxxx>
> + descs_size = struct_size(descs, desc, count);
> + bitmap_size = BITS_TO_LONGS(max(gdev->ngpio, count));
> + alloc_size = descs_size + struct_size(array_info, invert_mask, 3 * bitmap_size);
Nitpick:
I know this is not your code, but if you respin try to add a comment
here explaining this 3 * bitmap_size.
Yours,
Linus Walleij