Skip to content

Commit 8db4afe

Browse files
committed
iio:pressure:ms5611 Fix buffer element alignment
One of a class of bugs pointed out by Lars in a recent review. iio_push_to_buffers_with_timestamp assumes the buffer used is aligned to the size of the timestamp (8 bytes). This is not guaranteed in this driver which uses an array of smaller elements on the stack. Here there is no data leak possibility so use an explicit structure on the stack to ensure alignment and nice readable fashion. The forced alignment of ts isn't strictly necessary in this driver as the padding will be correct anyway (there isn't any). However it is probably less fragile to have it there and it acts as documentation of the requirement. Fixes: 713bbb4 ("iio: pressure: ms5611: Add triggered buffer support") Reported-by: Lars-Peter Clausen <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]> Acked-by: Tomasz Duszynski <[email protected]> Cc: <[email protected]>
1 parent 5c49056 commit 8db4afe

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/iio/pressure/ms5611_core.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,21 @@ static irqreturn_t ms5611_trigger_handler(int irq, void *p)
212212
struct iio_poll_func *pf = p;
213213
struct iio_dev *indio_dev = pf->indio_dev;
214214
struct ms5611_state *st = iio_priv(indio_dev);
215-
s32 buf[4]; /* s32 (pressure) + s32 (temp) + 2 * s32 (timestamp) */
215+
/* Ensure buffer elements are naturally aligned */
216+
struct {
217+
s32 channels[2];
218+
s64 ts __aligned(8);
219+
} scan;
216220
int ret;
217221

218222
mutex_lock(&st->lock);
219-
ret = ms5611_read_temp_and_pressure(indio_dev, &buf[1], &buf[0]);
223+
ret = ms5611_read_temp_and_pressure(indio_dev, &scan.channels[1],
224+
&scan.channels[0]);
220225
mutex_unlock(&st->lock);
221226
if (ret < 0)
222227
goto err;
223228

224-
iio_push_to_buffers_with_timestamp(indio_dev, buf,
229+
iio_push_to_buffers_with_timestamp(indio_dev, &scan,
225230
iio_get_time_ns(indio_dev));
226231

227232
err:

0 commit comments

Comments
 (0)