Skip to content

Commit f960139

Browse files
Jonathan Camerongregkh
authored andcommitted
iio: magn: bmc150: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
[ Upstream commit 7692088 ] To make code more readable, use a structure to express the channel layout and ensure the timestamp is 8 byte aligned. Found during an audit of all calls of uses of iio_push_to_buffers_with_timestamp() Fixes: c91746a ("iio: magn: Add support for BMC150 magnetometer") Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Cc: Stephan Gerhold <stephan@gerhold.net> Cc: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20210501170121.512209-17-jic23@kernel.org Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent e5e102f commit f960139

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎drivers/iio/magnetometer/bmc150_magn.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,11 @@ struct bmc150_magn_data {
136136
struct mutex mutex;
137137
struct regmap *regmap;
138138
struct iio_mount_matrix orientation;
139-
/* 4 x 32 bits for x, y z, 4 bytes align, 64 bits timestamp */
140-
s32 buffer[6];
139+
/* Ensure timestamp is naturally aligned */
140+
struct {
141+
s32 chans[3];
142+
s64 timestamp __aligned(8);
143+
} scan;
141144
struct iio_trigger *dready_trig;
142145
bool dready_trigger_on;
143146
int max_odr;
@@ -673,11 +676,11 @@ static irqreturn_t bmc150_magn_trigger_handler(int irq, void *p)
673676
int ret;
674677

675678
mutex_lock(&data->mutex);
676-
ret = bmc150_magn_read_xyz(data, data->buffer);
679+
ret = bmc150_magn_read_xyz(data, data->scan.chans);
677680
if (ret < 0)
678681
goto err;
679682

680-
iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
683+
iio_push_to_buffers_with_timestamp(indio_dev, &data->scan,
681684
pf->timestamp);
682685

683686
err:

0 commit comments

Comments
 (0)