Re: [libgpiod][PATCH] treewide: rework struct gpiod_line_bulk

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 23, 2020 at 2:39 PM Bartosz Golaszewski <brgl@xxxxxxxx> wrote:
> On Fri, Oct 23, 2020 at 12:24 PM Andy Shevchenko
> <andy.shevchenko@xxxxxxxxx> wrote:
> > On Fri, Oct 23, 2020 at 12:31 PM Bartosz Golaszewski <brgl@xxxxxxxx> wrote:

...

> > > +struct gpiod_line_bulk {
> > > +       struct gpiod_chip *owner;
> > > +       unsigned int num_lines;
> > > +       unsigned int max_lines;
> > > +       struct gpiod_line *lines[1];
> >
> > Why not '[]' as we do in the kernel?
> >
>
> Because I want to be able to store a single line in this structure if I do:
>
>     struct gpiod_line_bulk bulk;
>
> Using [] makes the size of this structure not take into account the
> last array member.
>
> > > +};
> >
> > > +#define BULK_SINGLE_LINE_INIT(line) \
> > > +               { gpiod_line_get_chip(line), 1, 1, { (line) } }
> >
> > Hmm... Perhaps union can help here?
> >
> > union {
> >   struct *lines[];
> >   struct *line;
> > }
> >
> > num_lines == 1 exactly defines this.
> >
>
> Nope because gcc will scream:
>
> error: flexible array member in union

Ah, of course. Should be
  struct ... **lines;

-- 
With Best Regards,
Andy Shevchenko



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux