Re: [PATCH v3 7/8] gpiolib: use bitmap_zalloc() for fastpath bitmaps
From: Linus Walleij
Date: Fri Nov 06 2026 - 09:01:39 EST
On Fri, Nov 6, 2026 at 7:30 AM Dmitry Torokhov
<dmitry.torokhov@xxxxxxxxx> wrote:
> Currently, struct gpio_array embeds invert_mask[] as a flexible array
> member, and gpio_descs_alloc() allocates the descriptor array,
> struct gpio_array, and all three fastpath bitmaps in a single kzalloc()
> call using manual BITS_TO_LONGS() calculations and pointer arithmetic.
> This exposes gpiolib to the underlying unsigned long representation
> used by bitmaps rather than respecting the bitmap abstraction.
>
> Convert invert_mask in struct gpio_array to a pointer and allocate each
> of the three fastpath bitmaps individually via bitmap_zalloc(), freeing
> them via bitmap_free() on fastpath cancellation and array disposal.
>
> Although this adds three slab allocations when the fastpath is active,
> packing all three masks into a single bitmap_zalloc() call would still
> require rounding the bit count up to BITS_PER_LONG and slicing the
> buffer with unsigned long pointer arithmetic, adding a second
> allocation and extra free paths without achieving bitmap API
> abstraction.
>
> Suggested-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
Reviewed-by: Linus Walleij <linusw@xxxxxxxxxx>
Yours,
Linus Walleij