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

From: Andy Shevchenko

Date: Mon Mar 16 2026 - 10:18:49 EST


On Sun, Mar 15, 2026 at 03:45:09PM -0700, Rosen Penev wrote:
> Allows using struct_size to simplify allocation slightly.
>
> Removes a pointer from the struct.

...

> - 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?


I rather would see two times array_size() than the above.

> sizeof_priv += sizeof_ext_info;

--
With Best Regards,
Andy Shevchenko