iio: accel: stk8ba50: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
[ Upstream commit 334883894bc1e145a1e0f5de1b0d1b6a1133f0e6 ]
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 this function.
Fixes: db6a19b825
("iio: accel: Add trigger support for STK8BA50")
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210501170121.512209-8-jic23@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
cd62282a51
commit
f0bc78df4a
@@ -91,12 +91,11 @@ struct stk8ba50_data {
|
|||||||
u8 sample_rate_idx;
|
u8 sample_rate_idx;
|
||||||
struct iio_trigger *dready_trig;
|
struct iio_trigger *dready_trig;
|
||||||
bool dready_trigger_on;
|
bool dready_trigger_on;
|
||||||
/*
|
/* Ensure timestamp is naturally aligned */
|
||||||
* 3 x 16-bit channels (10-bit data, 6-bit padding) +
|
struct {
|
||||||
* 1 x 16 padding +
|
s16 chans[3];
|
||||||
* 4 x 16 64-bit timestamp
|
s64 timetamp __aligned(8);
|
||||||
*/
|
} scan;
|
||||||
s16 buffer[8];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define STK8BA50_ACCEL_CHANNEL(index, reg, axis) { \
|
#define STK8BA50_ACCEL_CHANNEL(index, reg, axis) { \
|
||||||
@@ -324,7 +323,7 @@ static irqreturn_t stk8ba50_trigger_handler(int irq, void *p)
|
|||||||
ret = i2c_smbus_read_i2c_block_data(data->client,
|
ret = i2c_smbus_read_i2c_block_data(data->client,
|
||||||
STK8BA50_REG_XOUT,
|
STK8BA50_REG_XOUT,
|
||||||
STK8BA50_ALL_CHANNEL_SIZE,
|
STK8BA50_ALL_CHANNEL_SIZE,
|
||||||
(u8 *)data->buffer);
|
(u8 *)data->scan.chans);
|
||||||
if (ret < STK8BA50_ALL_CHANNEL_SIZE) {
|
if (ret < STK8BA50_ALL_CHANNEL_SIZE) {
|
||||||
dev_err(&data->client->dev, "register read failed\n");
|
dev_err(&data->client->dev, "register read failed\n");
|
||||||
goto err;
|
goto err;
|
||||||
@@ -337,10 +336,10 @@ static irqreturn_t stk8ba50_trigger_handler(int irq, void *p)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
data->buffer[i++] = ret;
|
data->scan.chans[i++] = ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
|
iio_push_to_buffers_with_timestamp(indio_dev, &data->scan,
|
||||||
pf->timestamp);
|
pf->timestamp);
|
||||||
err:
|
err:
|
||||||
mutex_unlock(&data->lock);
|
mutex_unlock(&data->lock);
|
||||||
|
Reference in New Issue
Block a user