Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: accel: kionix-kx022a: use iio_push_to_buffers_with_ts()
@ 2026-08-18 15:56 Gabriel Rondon
  2026-08-18 16:16 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Gabriel Rondon @ 2026-08-18 15:56 UTC (permalink / raw)
  To: Matti Vaittinen, Jonathan Cameron
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	linux-kernel

Replace the deprecated iio_push_to_buffers_with_timestamp() with
iio_push_to_buffers_with_ts(), which takes the destination buffer size
and checks it against scan_bytes at runtime.

Both push sites already use suitably sized and aligned storage: the FIFO
flush path pushes data->scan ({ __le16 channels[3]; aligned_s64 ts; }),
and the trigger handler pushes data->buffer (__le16[8], aligned to
IIO_DMA_MINALIGN). Both are 16 bytes, which matches scan_bytes for the
3-axis plus s64 timestamp layout used by all supported variants, so pass
sizeof() for each.

Signed-off-by: Gabriel Rondon <grondon@gmail.com>
---
 drivers/iio/accel/kionix-kx022a.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c
index 02dd1db7a646..ed0fffd83d3f 100644
--- a/drivers/iio/accel/kionix-kx022a.c
+++ b/drivers/iio/accel/kionix-kx022a.c
@@ -864,7 +864,8 @@ static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples,
 		for_each_set_bit(bit, idev->active_scan_mask, AXIS_MAX)
 			chs[bit] = sam[bit];
 
-		iio_push_to_buffers_with_timestamp(idev, &data->scan, tstamp);
+		iio_push_to_buffers_with_ts(idev, &data->scan,
+					    sizeof(data->scan), tstamp);
 
 		tstamp += sample_period;
 	}
@@ -1034,7 +1035,8 @@ static irqreturn_t kx022a_trigger_handler(int irq, void *p)
 	if (ret < 0)
 		goto err_read;
 
-	iio_push_to_buffers_with_timestamp(idev, data->buffer, data->timestamp);
+	iio_push_to_buffers_with_ts(idev, data->buffer, sizeof(data->buffer),
+				    data->timestamp);
 err_read:
 	iio_trigger_notify_done(idev->trig);
 
-- 
2.50.1 (Apple Git-155)


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

* Re: [PATCH] iio: accel: kionix-kx022a: use iio_push_to_buffers_with_ts()
  2026-08-18 15:56 [PATCH] iio: accel: kionix-kx022a: use iio_push_to_buffers_with_ts() Gabriel Rondon
@ 2026-08-18 16:16 ` Jonathan Cameron
  2026-08-18 21:51   ` Gabriel Rondon
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2026-08-18 16:16 UTC (permalink / raw)
  To: Gabriel Rondon
  Cc: Matti Vaittinen, David Lechner, Nuno Sá, Andy Shevchenko,
	linux-iio, linux-kernel

On Tue, 18 Aug 2026 16:56:35 +0100
Gabriel Rondon <grondon@gmail.com> wrote:

> Replace the deprecated iio_push_to_buffers_with_timestamp() with
> iio_push_to_buffers_with_ts(), which takes the destination buffer size
> and checks it against scan_bytes at runtime.
> 
> Both push sites already use suitably sized and aligned storage: the FIFO
> flush path pushes data->scan ({ __le16 channels[3]; aligned_s64 ts; }),
> and the trigger handler pushes data->buffer (__le16[8], aligned to
> IIO_DMA_MINALIGN). Both are 16 bytes, which matches scan_bytes for the
> 3-axis plus s64 timestamp layout used by all supported variants, so pass
> sizeof() for each.

As is quite common with this sort of cleanup, it got me looking at
code that has evolved in an odd direction. In this case it was
you pointing out both buffers are same size and have same content!

Why do we have both scan and buffer?  The kx022a_trigger_handler()
could just as easily use scan (which is the cleaner solution here)

That leaves get_axis which uses st->buffer as well. Whilst it is a little
ugly, that can just use the first channel of scan as well.

If you are happy to do so could you make that change as a precursor
to this set?  I don't particularly want to leave that mess in place
now I've noticed it.

Thanks,

Jonathan

 
> 
> Signed-off-by: Gabriel Rondon <grondon@gmail.com>
> ---
>  drivers/iio/accel/kionix-kx022a.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c
> index 02dd1db7a646..ed0fffd83d3f 100644
> --- a/drivers/iio/accel/kionix-kx022a.c
> +++ b/drivers/iio/accel/kionix-kx022a.c
> @@ -864,7 +864,8 @@ static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples,
>  		for_each_set_bit(bit, idev->active_scan_mask, AXIS_MAX)
>  			chs[bit] = sam[bit];
>  
> -		iio_push_to_buffers_with_timestamp(idev, &data->scan, tstamp);
> +		iio_push_to_buffers_with_ts(idev, &data->scan,
> +					    sizeof(data->scan), tstamp);
>  
>  		tstamp += sample_period;
>  	}
> @@ -1034,7 +1035,8 @@ static irqreturn_t kx022a_trigger_handler(int irq, void *p)
>  	if (ret < 0)
>  		goto err_read;
>  
> -	iio_push_to_buffers_with_timestamp(idev, data->buffer, data->timestamp);
> +	iio_push_to_buffers_with_ts(idev, data->buffer, sizeof(data->buffer),
> +				    data->timestamp);
>  err_read:
>  	iio_trigger_notify_done(idev->trig);
>  


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

* Re: [PATCH] iio: accel: kionix-kx022a: use iio_push_to_buffers_with_ts()
  2026-08-18 16:16 ` Jonathan Cameron
@ 2026-08-18 21:51   ` Gabriel Rondon
  0 siblings, 0 replies; 3+ messages in thread
From: Gabriel Rondon @ 2026-08-18 21:51 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Matti Vaittinen, David Lechner, Nuno Sá, Andy Shevchenko,
	linux-iio, linux-kernel

On Tue, 18 Aug 2026 17:16:57 +0100
Jonathan Cameron <jic23@kernel.org> wrote:

> Why do we have both scan and buffer? The kx022a_trigger_handler()
> could just as easily use scan (which is the cleaner solution here)
>
> That leaves get_axis which uses st->buffer as well. Whilst it is a little
> ugly, that can just use the first channel of scan as well.
>
> If you are happy to do so could you make that change as a precursor
> to this set?

Happy to. v2 splits it into a precursor that drops buffer and routes
both the one-shot read and the triggered handler through scan (moving
the IIO_DMA_MINALIGN alignment onto scan), then the conversion on top.

Thanks,
Gabriel

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

end of thread, other threads:[~2026-08-18 21:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-18 15:56 [PATCH] iio: accel: kionix-kx022a: use iio_push_to_buffers_with_ts() Gabriel Rondon
2026-08-18 16:16 ` Jonathan Cameron
2026-08-18 21:51   ` Gabriel Rondon

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