Skip to content

Commit 4c06967

Browse files
committed
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: 3904b28 ("iio: gyro: Add driver for the MPU-3050 gyroscope") Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/20210613151039.569883-4-jic23@kernel.org
1 parent f3e1a57 commit 4c06967

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

drivers/iio/gyro/mpu3050-core.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,10 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p)
471471
struct iio_dev *indio_dev = pf->indio_dev;
472472
struct mpu3050 *mpu3050 = iio_priv(indio_dev);
473473
int ret;
474-
/*
475-
* Temperature 1*16 bits
476-
* Three axes 3*16 bits
477-
* Timestamp 64 bits (4*16 bits)
478-
* Sum total 8*16 bits
479-
*/
480-
__be16 hw_values[8];
474+
struct {
475+
__be16 chans[4];
476+
s64 timestamp __aligned(8);
477+
} scan;
481478
s64 timestamp;
482479
unsigned int datums_from_fifo = 0;
483480

@@ -572,9 +569,10 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p)
572569
fifo_values[4]);
573570

574571
/* Index past the footer (fifo_values[0]) and push */
575-
iio_push_to_buffers_with_timestamp(indio_dev,
576-
&fifo_values[1],
577-
timestamp);
572+
iio_push_to_buffers_with_ts_unaligned(indio_dev,
573+
&fifo_values[1],
574+
sizeof(__be16) * 4,
575+
timestamp);
578576

579577
fifocnt -= toread;
580578
datums_from_fifo++;
@@ -632,15 +630,15 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p)
632630
goto out_trigger_unlock;
633631
}
634632

635-
ret = regmap_bulk_read(mpu3050->map, MPU3050_TEMP_H, &hw_values,
636-
sizeof(hw_values));
633+
ret = regmap_bulk_read(mpu3050->map, MPU3050_TEMP_H, scan.chans,
634+
sizeof(scan.chans));
637635
if (ret) {
638636
dev_err(mpu3050->dev,
639637
"error reading axis data\n");
640638
goto out_trigger_unlock;
641639
}
642640

643-
iio_push_to_buffers_with_timestamp(indio_dev, hw_values, timestamp);
641+
iio_push_to_buffers_with_timestamp(indio_dev, &scan, timestamp);
644642

645643
out_trigger_unlock:
646644
mutex_unlock(&mpu3050->lock);

0 commit comments

Comments
 (0)