Re: [PATCH] iio: iio-mux: use flexible array member
From: Rosen Penev
Date: Mon Mar 16 2026 - 17:17:21 EST
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.
>
> > > I rather would see two times array_size() than the above.
>
> > OK
>
> > > > sizeof_priv += sizeof_ext_info;
>
> --
> With Best Regards,
> Andy Shevchenko
>
>