Re: [PATCH] iio: iio-mux: use flexible array member

From: Andy Shevchenko

Date: Mon Mar 16 2026 - 17:26:23 EST


On Mon, Mar 16, 2026 at 02:12:35PM -0700, Rosen Penev wrote:
> On Mon, Mar 16, 2026 at 12:43 PM Andy Shevchenko
> <andriy.shevchenko@xxxxxxxxx> wrote:
> > On Mon, Mar 16, 2026 at 11:11:22AM -0700, Rosen Penev wrote:
> > > On Mon, Mar 16, 2026 at 7:16 AM Andy Shevchenko
> > > <andriy.shevchenko@xxxxxxxxx> wrote:
> > > > On Sun, Mar 15, 2026 at 03:45:09PM -0700, Rosen Penev wrote:

...

> > > > > - sizeof_priv = sizeof(*mux);
> > > > > - sizeof_priv += sizeof(*mux->child) * children;
> > > > > + sizeof_priv = struct_size(mux, child, children);
> > > > > sizeof_priv += sizeof(*mux->chan) * children;
> > > >
> > > > There are two arrays that are allocated at the end of the same object.
> > > > Why is mux better than the chan?
> > > It's how it's already laid out. mux first and then the other data.
> >
> > It doesn't matter, right?
> I can't really judge. This commit came from running
>
> git grep \\\*\)\ | grep \ \+\ 1\)\;
>
> which is the pre-C99 way of doing trailing allocations.
>
> Shuffling this around would increase the patch size which I've been
> advised against doing elsewhere.

My point was to show that from the memory layout the mux first chan next and
vice versa have no differences. Hence the proposed patch actually changes the
status quo. What I suggested is to keep a status quo and use array_size()
instead.

sizeof_priv = sizeof(mux);
sizeof_priv += array_size(child);
sizeof_priv += array_size(chan);

> > > > I rather would see two times array_size() than the above.
> >
> > > OK
> >
> > > > > sizeof_priv += sizeof_ext_info;

--
With Best Regards,
Andy Shevchenko