Commit b5ca2046 authored by Jonathan Cameron's avatar Jonathan Cameron

iio: gyro: mpu3050: Fix alignment and size issues with buffers.

Fix a set of closely related issues.
1. When using fifo_values() there was not enough space for the timestamp to
   be inserted by iio_push_to_buffers_with_timestamp()
2. fifo_values() did not meet the alignment requirement of
   iio_push_to_buffers_with_timestamp()
3. hw_values did not meet the alignment requirement either.

1 and 2 fixed by using new iio_push_to_buffers_with_ts_unaligned() which has
no alignment or space padding requirements.
3 fixed by introducing a structure that makes the space and alignment
requirements explicit.

Fixes: 3904b28e ("iio: gyro: Add driver for the MPU-3050 gyroscope")
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20210613151039.569883-4-jic23@kernel.org
parent cbe5c697
...@@ -471,13 +471,10 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p) ...@@ -471,13 +471,10 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p)
struct iio_dev *indio_dev = pf->indio_dev; struct iio_dev *indio_dev = pf->indio_dev;
struct mpu3050 *mpu3050 = iio_priv(indio_dev); struct mpu3050 *mpu3050 = iio_priv(indio_dev);
int ret; int ret;
/* struct {
* Temperature 1*16 bits __be16 chans[4];
* Three axes 3*16 bits s64 timestamp __aligned(8);
* Timestamp 64 bits (4*16 bits) } scan;
* Sum total 8*16 bits
*/
__be16 hw_values[8];
s64 timestamp; s64 timestamp;
unsigned int datums_from_fifo = 0; unsigned int datums_from_fifo = 0;
...@@ -572,9 +569,10 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p) ...@@ -572,9 +569,10 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p)
fifo_values[4]); fifo_values[4]);
/* Index past the footer (fifo_values[0]) and push */ /* Index past the footer (fifo_values[0]) and push */
iio_push_to_buffers_with_timestamp(indio_dev, iio_push_to_buffers_with_ts_unaligned(indio_dev,
&fifo_values[1], &fifo_values[1],
timestamp); sizeof(__be16) * 4,
timestamp);
fifocnt -= toread; fifocnt -= toread;
datums_from_fifo++; datums_from_fifo++;
...@@ -632,15 +630,15 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p) ...@@ -632,15 +630,15 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p)
goto out_trigger_unlock; goto out_trigger_unlock;
} }
ret = regmap_bulk_read(mpu3050->map, MPU3050_TEMP_H, &hw_values, ret = regmap_bulk_read(mpu3050->map, MPU3050_TEMP_H, scan.chans,
sizeof(hw_values)); sizeof(scan.chans));
if (ret) { if (ret) {
dev_err(mpu3050->dev, dev_err(mpu3050->dev,
"error reading axis data\n"); "error reading axis data\n");
goto out_trigger_unlock; goto out_trigger_unlock;
} }
iio_push_to_buffers_with_timestamp(indio_dev, hw_values, timestamp); iio_push_to_buffers_with_timestamp(indio_dev, &scan, timestamp);
out_trigger_unlock: out_trigger_unlock:
mutex_unlock(&mpu3050->lock); mutex_unlock(&mpu3050->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment