IIO: Alignment fixes part 1 - sizes too small as well.
Subsystems (3)
Jonathan Cameron
maintainercover 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.
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
Jonathan Cameron
maintainerPATCH 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()
--- drivers/iio/adc/ad7768-1.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/iio/adc/ad7768-1.c +6 -2
@@ -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
Jonathan Cameron
maintainerPATCH 2/2 iio: adc: ad7923: Fix undersized rx buffer.
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Fixes tag is where the max channels became 8, but timestamp space was missing before that.
--- drivers/iio/adc/ad7923.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/ad7923.c +3 -1
@@ -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
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
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.Reviewed-by Andy Shevchenko <[email protected]>
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