lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 4 Oct 2021 15:38:29 +0200
From:   Geert Uytterhoeven <geert@...ux-m68k.org>
To:     Andy Shevchenko <andy.shevchenko@...il.com>
Cc:     Linus Walleij <linus.walleij@...aro.org>,
        Bartosz Golaszewski <bgolaszewski@...libre.com>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        "open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] gpio: aggregator: Wrap access to gpiochip_fwd.tmp[]

Hi Andy,

On Mon, Oct 4, 2021 at 3:23 PM Andy Shevchenko
<andy.shevchenko@...il.com> wrote:
> On Mon, Oct 4, 2021 at 3:47 PM Geert Uytterhoeven
> <geert+renesas@...der.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()?

That's not sufficient: the bitmap is only one part. There are one
fixed-size and two variable-size objects to allocate.
Yes, they can be allocated separately, at the expense of more
allocations, and more data (pointers) to allocate to keep track of
all those objects.

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

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ