Re: [PATCH] gpiolib: use __counted_by() for GPIO descriptors

From: Bartosz Golaszewski
Date: Wed Dec 20 2023 - 07:36:10 EST


On Wed, Dec 20, 2023 at 9:16 AM Bartosz Golaszewski <brgl@xxxxxxxx> wrote:
>
> On Tue, Dec 19, 2023 at 4:12 PM Andy Shevchenko
> <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
> >
> > On Tue, Dec 19, 2023 at 01:57:06PM +0100, Bartosz Golaszewski wrote:
> > > From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
> > >
> > > Pull the array of GPIO descriptors into struct gpio_device as a flexible
> > > array and use __counted_by() to control its size.
> >
> > How big is the struct gpio_device? Unifying like this might provoke subtle
> > errors on very fragmented memory, where k*alloc() might not find enough free
> > space. Note, k*alloc() guarantees finding only memory for a single page.
> > With PAGE_SIZE = 4k, this might be an issue.
> >
> > I would suggest, if nothing prevents us from switching, to use kvmalloc().
> >
>
> That's a good point but there's another thing. We need to call
> gpiochip_get_ngpios() before the allocation. I need to revisit this
> one.
>

It's trickier than I thought. We need the struct device to exist (have
its software node assigned) before we check the property but we cannot
allocate gdev (embedding struct device) + descs before we have read
it. Eh, maybe it's not worth it and let's keep the two allocations
separate.

Bart

> Bart
>
> > --
> > With Best Regards,
> > Andy Shevchenko
> >
> >