linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] IIO: Alignment fixes part 1 - sizes too small as well.
@ 2021-05-01 16:53 Jonathan Cameron
  2021-05-01 16:53 ` [PATCH 1/2] iio: adc: ad7768-1: Fix too small buffer passed to iio_push_to_buffers_with_timestamp() Jonathan Cameron
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jonathan Cameron @ 2021-05-01 16:53 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron, Daniel Junho

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

I finally got around to do a manual audit of all the calls to
iio_push_to_buffers_with_timestamp() which has the somewhat odd requirements
of:
1. 8 byte alignment of the provided buffer.
2. space for an 8 byte naturally aligned timestamp to be inserted at the
   end.

As discussed previous in
https://lore.kernel.org/linux-iio/20200920112742.170751-1-jic23@kernel.org/
it is not easy to fix the alignment issue without requiring a bounce buffer
(see part 4 of the alignment fixes for a proposal for that where it is
absolutely necessary).

In these cases the buffer is neither big enough, nor correctly aligned
so fix both issues in one go.

Cc: Daniel Junho <djunho@gmail.com>

Jonathan Cameron (2):
  iio: adc: ad7768-1: Fix too small buffer passed to
    iio_push_to_buffers_with_timestamp()
  iio: adc: ad7923: Fix undersized rx buffer.

 drivers/iio/adc/ad7768-1.c | 8 ++++++--
 drivers/iio/adc/ad7923.c   | 4 +++-
 2 files changed, 9 insertions(+), 3 deletions(-)

-- 
2.31.1


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

* [PATCH 1/2] iio: adc: ad7768-1: Fix too small buffer passed to iio_push_to_buffers_with_timestamp()
  2021-05-01 16:53 [PATCH 0/2] IIO: Alignment fixes part 1 - sizes too small as well Jonathan Cameron
@ 2021-05-01 16:53 ` Jonathan Cameron
  2021-05-01 16:53 ` [PATCH 2/2] iio: adc: ad7923: Fix undersized rx buffer Jonathan Cameron
  2021-05-01 19:14 ` [PATCH 0/2] IIO: Alignment fixes part 1 - sizes too small as well Andy Shevchenko
  2 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2021-05-01 16:53 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Add space for the timestamp to be inserted.  Also ensure correct
alignment for passing to iio_push_to_buffers_with_timestamp()

Fixes: a5f8c7da3dbe ("iio: adc: Add AD7768-1 ADC basic support")
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/adc/ad7768-1.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
index c945f1349623..60f21fed6dcb 100644
--- a/drivers/iio/adc/ad7768-1.c
+++ b/drivers/iio/adc/ad7768-1.c
@@ -167,6 +167,10 @@ struct ad7768_state {
 	 * transfer buffers to live in their own cache lines.
 	 */
 	union {
+		struct {
+			__be32 chan;
+			s64 timestamp;
+		} scan;
 		__be32 d32;
 		u8 d8[2];
 	} data ____cacheline_aligned;
@@ -469,11 +473,11 @@ static irqreturn_t ad7768_trigger_handler(int irq, void *p)
 
 	mutex_lock(&st->lock);
 
-	ret = spi_read(st->spi, &st->data.d32, 3);
+	ret = spi_read(st->spi, &st->data.scan.chan, 3);
 	if (ret < 0)
 		goto err_unlock;
 
-	iio_push_to_buffers_with_timestamp(indio_dev, &st->data.d32,
+	iio_push_to_buffers_with_timestamp(indio_dev, &st->data.scan,
 					   iio_get_time_ns(indio_dev));
 
 	iio_trigger_notify_done(indio_dev->trig);
-- 
2.31.1


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

* [PATCH 2/2] iio: adc: ad7923: Fix undersized rx buffer.
  2021-05-01 16:53 [PATCH 0/2] IIO: Alignment fixes part 1 - sizes too small as well Jonathan Cameron
  2021-05-01 16:53 ` [PATCH 1/2] iio: adc: ad7768-1: Fix too small buffer passed to iio_push_to_buffers_with_timestamp() Jonathan Cameron
@ 2021-05-01 16:53 ` Jonathan Cameron
  2021-05-01 19:14 ` [PATCH 0/2] IIO: Alignment fixes part 1 - sizes too small as well Andy Shevchenko
  2 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2021-05-01 16:53 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron, Daniel Junho

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Fixes tag is where the max channels became 8, but timestamp space was missing
before that.

Fixes: 851644a60d20 ("iio: adc: ad7923: Add support for the ad7908/ad7918/ad7928")
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Daniel Junho <djunho@gmail.com>
---
 drivers/iio/adc/ad7923.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
index 9a649745cd0a..069b561ee768 100644
--- a/drivers/iio/adc/ad7923.c
+++ b/drivers/iio/adc/ad7923.c
@@ -59,8 +59,10 @@ struct ad7923_state {
 	/*
 	 * DMA (thus cache coherency maintenance) requires the
 	 * transfer buffers to live in their own cache lines.
+	 * Ensure rx_buf can be directly used in iio_push_to_buffers_with_timetamp
+	 * Length = 8 channels + 4 extra for 8 byte timestamp
 	 */
-	__be16				rx_buf[4] ____cacheline_aligned;
+	__be16				rx_buf[12] ____cacheline_aligned;
 	__be16				tx_buf[4];
 };
 
-- 
2.31.1


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

* Re: [PATCH 0/2] IIO: Alignment fixes part 1 - sizes too small as well.
  2021-05-01 16:53 [PATCH 0/2] IIO: Alignment fixes part 1 - sizes too small as well Jonathan Cameron
  2021-05-01 16:53 ` [PATCH 1/2] iio: adc: ad7768-1: Fix too small buffer passed to iio_push_to_buffers_with_timestamp() Jonathan Cameron
  2021-05-01 16:53 ` [PATCH 2/2] iio: adc: ad7923: Fix undersized rx buffer Jonathan Cameron
@ 2021-05-01 19:14 ` Andy Shevchenko
  2021-05-13 17:14   ` Jonathan Cameron
  2 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2021-05-01 19:14 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Jonathan Cameron, Daniel Junho

On Sat, May 1, 2021 at 7:55 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> I finally got around to do a manual audit of all the calls to
> iio_push_to_buffers_with_timestamp() which has the somewhat odd requirements
> of:
> 1. 8 byte alignment of the provided buffer.
> 2. space for an 8 byte naturally aligned timestamp to be inserted at the
>    end.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> As discussed previous in
> https://lore.kernel.org/linux-iio/20200920112742.170751-1-jic23@kernel.org/
> it is not easy to fix the alignment issue without requiring a bounce buffer
> (see part 4 of the alignment fixes for a proposal for that where it is
> absolutely necessary).
>
> In these cases the buffer is neither big enough, nor correctly aligned
> so fix both issues in one go.
>
> Cc: Daniel Junho <djunho@gmail.com>
>
> Jonathan Cameron (2):
>   iio: adc: ad7768-1: Fix too small buffer passed to
>     iio_push_to_buffers_with_timestamp()
>   iio: adc: ad7923: Fix undersized rx buffer.
>
>  drivers/iio/adc/ad7768-1.c | 8 ++++++--
>  drivers/iio/adc/ad7923.c   | 4 +++-
>  2 files changed, 9 insertions(+), 3 deletions(-)
>
> --
> 2.31.1
>


-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH 0/2] IIO: Alignment fixes part 1 - sizes too small as well.
  2021-05-01 19:14 ` [PATCH 0/2] IIO: Alignment fixes part 1 - sizes too small as well Andy Shevchenko
@ 2021-05-13 17:14   ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2021-05-13 17:14 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-iio, Jonathan Cameron, Daniel Junho

On Sat, 1 May 2021 22:14:16 +0300
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> On Sat, May 1, 2021 at 7:55 PM Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > I finally got around to do a manual audit of all the calls to
> > iio_push_to_buffers_with_timestamp() which has the somewhat odd requirements
> > of:
> > 1. 8 byte alignment of the provided buffer.
> > 2. space for an 8 byte naturally aligned timestamp to be inserted at the
> >    end.  
> 
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Thanks!

Applied to the fixes-togreg branch of iio.git and marked for stable.

For these two I decided to go the quick way as they are broken even on systems
where the alignment issue doesn't matter.

Thanks,

Jonathan

> 
> > As discussed previous in
> > https://lore.kernel.org/linux-iio/20200920112742.170751-1-jic23@kernel.org/
> > it is not easy to fix the alignment issue without requiring a bounce buffer
> > (see part 4 of the alignment fixes for a proposal for that where it is
> > absolutely necessary).
> >
> > In these cases the buffer is neither big enough, nor correctly aligned
> > so fix both issues in one go.
> >
> > Cc: Daniel Junho <djunho@gmail.com>
> >
> > Jonathan Cameron (2):
> >   iio: adc: ad7768-1: Fix too small buffer passed to
> >     iio_push_to_buffers_with_timestamp()
> >   iio: adc: ad7923: Fix undersized rx buffer.
> >
> >  drivers/iio/adc/ad7768-1.c | 8 ++++++--
> >  drivers/iio/adc/ad7923.c   | 4 +++-
> >  2 files changed, 9 insertions(+), 3 deletions(-)
> >
> > --
> > 2.31.1
> >  
> 
> 


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

end of thread, other threads:[~2021-05-13 17:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-01 16:53 [PATCH 0/2] IIO: Alignment fixes part 1 - sizes too small as well Jonathan Cameron
2021-05-01 16:53 ` [PATCH 1/2] iio: adc: ad7768-1: Fix too small buffer passed to iio_push_to_buffers_with_timestamp() Jonathan Cameron
2021-05-01 16:53 ` [PATCH 2/2] iio: adc: ad7923: Fix undersized rx buffer Jonathan Cameron
2021-05-01 19:14 ` [PATCH 0/2] IIO: Alignment fixes part 1 - sizes too small as well Andy Shevchenko
2021-05-13 17:14   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).