Skip to content

Commit 95ad675

Browse files
committed
iio: accel: kxsd9: Fix alignment of local buffer.
iio_push_to_buffers_with_timestamp assumes 8 byte alignment which is not guaranteed by an array of smaller elements. Note that whilst in this particular case the alignment forcing of the ts element is not strictly necessary it acts as good documentation. Doing this where not necessary should cut down on the number of cut and paste introduced errors elsewhere. Fixes: 0427a10 ("iio: accel: kxsd9: Add triggered buffer handling") Reported-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Cc: <Stable@vger.kernel.org>
1 parent e3ea419 commit 95ad675

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

drivers/iio/accel/kxsd9.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,22 +209,28 @@ static irqreturn_t kxsd9_trigger_handler(int irq, void *p)
209209
const struct iio_poll_func *pf = p;
210210
struct iio_dev *indio_dev = pf->indio_dev;
211211
struct kxsd9_state *st = iio_priv(indio_dev);
212+
/*
213+
* Ensure correct positioning and alignment of timestamp.
214+
* No need to zero initialize as all elements written.
215+
*/
216+
struct {
217+
__be16 chan[4];
218+
s64 ts __aligned(8);
219+
} hw_values;
212220
int ret;
213-
/* 4 * 16bit values AND timestamp */
214-
__be16 hw_values[8];
215221

216222
ret = regmap_bulk_read(st->map,
217223
KXSD9_REG_X,
218-
&hw_values,
219-
8);
224+
hw_values.chan,
225+
sizeof(hw_values.chan));
220226
if (ret) {
221227
dev_err(st->dev,
222228
"error reading data\n");
223229
return ret;
224230
}
225231

226232
iio_push_to_buffers_with_timestamp(indio_dev,
227-
hw_values,
233+
&hw_values,
228234
iio_get_time_ns(indio_dev));
229235
iio_trigger_notify_done(indio_dev->trig);
230236

0 commit comments

Comments
 (0)