lkml.org 
[lkml]   [2021]   [Oct]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] gpio: aggregator: Wrap access to gpiochip_fwd.tmp[]
On Mon, Oct 4, 2021 at 3:47 PM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
>
> The tmp[] member of the gpiochip_fwd structure is used to store both the
> temporary values bitmap and the desc pointers for operations on multiple
> GPIOs. As both are arrays with sizes unknown at compile-time, accessing
> them requires offset calculations, which are currently duplicated in
> gpio_fwd_get_multiple() and gpio_fwd_set_multiple().
>
> Introduce (a) accessors for both arrays and (b) a macro to calculate the
> needed storage size. This confines the layout of the tmp[] member into
> a single spot, to ease maintenance.

...

> +#define fwd_tmp_descs(fwd) (void *)&(fwd)->tmp[BITS_TO_LONGS((fwd)->chip.ngpio)]
> +
> +#define fwd_tmp_size(ngpios) (BITS_TO_LONGS((ngpios)) + (ngpios))

...

> - fwd = devm_kzalloc(dev, struct_size(fwd, tmp,
> - BITS_TO_LONGS(ngpios) + ngpios), GFP_KERNEL);
> + fwd = devm_kzalloc(dev, struct_size(fwd, tmp, fwd_tmp_size(ngpios)),
> + GFP_KERNEL);

Shouldn't we rather use devm_bitmap_zalloc() / bitmap_free()?

> if (!fwd)
> return ERR_PTR(-ENOMEM);


--
With Best Regards,
Andy Shevchenko

\
 
 \ /
  Last update: 2021-10-04 15:50    [W:0.040 / U:2.828 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site