Skip to content

Commit 4c2d124

Browse files
committed
iio: imu: adis16400: Fix buffer alignment requirements.
iio_push_to_buffers_with_timestamp() requires that the buffer is 8 byte alignment to ensure an inserted timestamp is naturally aligned. This requirement was not met here when burst mode is in use beause of a leading u16. Use the new iio_push_to_buffers_with_ts_unaligned() function that has more relaxed requirements. It is somewhat complex to access that actual data length, but a safe bound can be found by using scan_bytes - sizeof(timestamp) so that is used in this path. More efficient approaches exist, but this ensure correctness at the cost of using a bounce buffer. Fixes: 5075e07 ("iio: imu: adis: generalize burst mode support") Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Nuno Sá <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20210613151039.569883-5-jic23@kernel.org
1 parent 4c06967 commit 4c2d124

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

drivers/iio/imu/adis16400.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,23 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)
641641
if (ret)
642642
dev_err(&adis->spi->dev, "Failed to read data: %d\n", ret);
643643

644-
if (st->variant->flags & ADIS16400_BURST_DIAG_STAT)
644+
if (st->variant->flags & ADIS16400_BURST_DIAG_STAT) {
645645
buffer = adis->buffer + sizeof(u16);
646-
else
647-
buffer = adis->buffer;
646+
/*
647+
* The size here is always larger than, or equal to the true
648+
* size of the channel data. This may result in a larger copy
649+
* than necessary, but as the target buffer will be
650+
* buffer->scan_bytes this will be safe.
651+
*/
652+
iio_push_to_buffers_with_ts_unaligned(indio_dev, buffer,
653+
indio_dev->scan_bytes - sizeof(pf->timestamp),
654+
pf->timestamp);
655+
} else {
656+
iio_push_to_buffers_with_timestamp(indio_dev,
657+
adis->buffer,
658+
pf->timestamp);
659+
}
648660

649-
iio_push_to_buffers_with_timestamp(indio_dev, buffer,
650-
pf->timestamp);
651661

652662
iio_trigger_notify_done(indio_dev->trig);
653663

0 commit comments

Comments
 (0)