Skip to contentSkip to conversation

IIO: Alignment fixes part 1 - sizes too small as well.

PATCH In review Jonathan Cameron 2 participants 5 messages May 1, 2021 – May 13, 2021

Subsystems (3)
lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

cover IIO: Alignment fixes part 1 - sizes too small as well.

From: Jonathan Cameron <[email protected]>

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/[email protected]/
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 <[email protected]>

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(-)
Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH 1/2 iio: adc: ad7768-1: Fix too small buffer passed to iio_push_to_buffers_with_timestamp()

From: Jonathan Cameron <[email protected]>

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")
---
 drivers/iio/adc/ad7768-1.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/iio/adc/ad7768-1.c +6 -2
index c945f1349623..60f21fed6dcb 100644
@@ -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);
Signature · 1 line
2.31.1
author maintainer
#2 lore raw

PATCH 2/2 iio: adc: ad7923: Fix undersized rx buffer.

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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")
Cc Daniel Junho <[email protected]>
---
 drivers/iio/adc/ad7923.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/ad7923.c +3 -1
index 9a649745cd0a..069b561ee768 100644
@@ -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];
 };
 
Signature · 1 line
2.31.1
Reviewed-by on the v1 series
#3 lore raw
In reply to Jonathan Cameron
Quoted 9 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Quoted 23 lines

As discussed previous in
https://lore.kernel.org/linux-iio/[email protected]/
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 <[email protected]>

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

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer Applied
#4 lore raw
Quoted 4 lines · On Sat, 1 May 2021 22:14:16 +0300 Andy Shevchenko <[email protected]>…
Quoted 3 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Quoted 8 lines
Quoted 6 lines

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.

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

Quoted 26 lines
Quoted 24 lines

As discussed previous in
https://lore.kernel.org/linux-iio/[email protected]/
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 <[email protected]>

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