public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2] iio: iio-mux: use flexible array member
@ 2026-03-16 23:29 Rosen Penev
  2026-03-17  7:26 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Rosen Penev @ 2026-03-16 23:29 UTC (permalink / raw)
  To: linux-iio
  Cc: Peter Rosin, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, open list

Make it clear that there's trailing data

Removes a pointer from the struct.

Use array_size for the sizeof calculations. Slightly cleaner.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 v2: use array_size
 drivers/iio/multiplexer/iio-mux.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/multiplexer/iio-mux.c b/drivers/iio/multiplexer/iio-mux.c
index b742ca9a99d1..f2bc8f3aad95 100644
--- a/drivers/iio/multiplexer/iio-mux.c
+++ b/drivers/iio/multiplexer/iio-mux.c
@@ -33,8 +33,8 @@ struct mux {
 	struct iio_channel *parent;
 	struct iio_chan_spec *chan;
 	struct iio_chan_spec_ext_info *ext_info;
-	struct mux_child *child;
 	u32 delay_us;
+	struct mux_child child[];
 };

 static int iio_mux_select(struct mux *mux, int idx)
@@ -381,8 +381,8 @@ static int mux_probe(struct platform_device *pdev)
 	}

 	sizeof_priv = sizeof(*mux);
-	sizeof_priv += sizeof(*mux->child) * children;
-	sizeof_priv += sizeof(*mux->chan) * children;
+	sizeof_priv += array_size(children, sizeof(*mux->child));
+	sizeof_priv += array_size(children, sizeof(*mux->chan));
 	sizeof_priv += sizeof_ext_info;

 	indio_dev = devm_iio_device_alloc(dev, sizeof_priv);
@@ -390,7 +390,6 @@ static int mux_probe(struct platform_device *pdev)
 		return -ENOMEM;

 	mux = iio_priv(indio_dev);
-	mux->child = (struct mux_child *)(mux + 1);
 	mux->chan = (struct iio_chan_spec *)(mux->child + children);

 	platform_set_drvdata(pdev, indio_dev);
--
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCHv2] iio: iio-mux: use flexible array member
  2026-03-16 23:29 [PATCHv2] iio: iio-mux: use flexible array member Rosen Penev
@ 2026-03-17  7:26 ` Andy Shevchenko
  2026-03-17 14:59   ` David Lechner
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2026-03-17  7:26 UTC (permalink / raw)
  To: Rosen Penev
  Cc: linux-iio, Peter Rosin, Jonathan Cameron, David Lechner,
	Nuno Sá, Andy Shevchenko, open list

On Mon, Mar 16, 2026 at 04:29:42PM -0700, Rosen Penev wrote:
> Make it clear that there's trailing data
> 
> Removes a pointer from the struct.
> 
> Use array_size for the sizeof calculations. Slightly cleaner.

array_size()
sizeof()

This commit message is poorly written. Please, consult with
https://chris.beams.io/git-commit on how to write better commit
messages.

...

> struct mux {

>  	struct iio_channel *parent;
>  	struct iio_chan_spec *chan;
>  	struct iio_chan_spec_ext_info *ext_info;
> -	struct mux_child *child;
>  	u32 delay_us;
> +	struct mux_child child[];
>  };

What's the point now to make it VLA? Again, why this and not the other one?

...

>  	mux = iio_priv(indio_dev);
> -	mux->child = (struct mux_child *)(mux + 1);
>  	mux->chan = (struct iio_chan_spec *)(mux->child + children);

(This piece linked to the above comment.)

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCHv2] iio: iio-mux: use flexible array member
  2026-03-17  7:26 ` Andy Shevchenko
@ 2026-03-17 14:59   ` David Lechner
  0 siblings, 0 replies; 3+ messages in thread
From: David Lechner @ 2026-03-17 14:59 UTC (permalink / raw)
  To: Andy Shevchenko, Rosen Penev
  Cc: linux-iio, Peter Rosin, Jonathan Cameron, Nuno Sá,
	Andy Shevchenko, open list

On 3/17/26 2:26 AM, Andy Shevchenko wrote:
> On Mon, Mar 16, 2026 at 04:29:42PM -0700, Rosen Penev wrote:
>> Make it clear that there's trailing data
>>
>> Removes a pointer from the struct.
>>
>> Use array_size for the sizeof calculations. Slightly cleaner.
> 
> array_size()
> sizeof()
> 
> This commit message is poorly written. Please, consult with
> https://chris.beams.io/git-commit on how to write better commit
> messages.
> 
> ...
> 
>> struct mux {
> 
>>  	struct iio_channel *parent;
>>  	struct iio_chan_spec *chan;
>>  	struct iio_chan_spec_ext_info *ext_info;
>> -	struct mux_child *child;
>>  	u32 delay_us;
>> +	struct mux_child child[];
>>  };
> 
> What's the point now to make it VLA? Again, why this and not the other one?

I agree with Andy here. It doesn't make much sense to use a variable length
array for one when there are other similar arrays in the same struct.


> 
> ...
> 
>>  	mux = iio_priv(indio_dev);
>> -	mux->child = (struct mux_child *)(mux + 1);
>>  	mux->chan = (struct iio_chan_spec *)(mux->child + children);
> 
> (This piece linked to the above comment.)
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-17 14:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-16 23:29 [PATCHv2] iio: iio-mux: use flexible array member Rosen Penev
2026-03-17  7:26 ` Andy Shevchenko
2026-03-17 14:59   ` David Lechner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox