Skip to content

Commit a5bf6fd

Browse files
committed
iio:chemical:sps30: Fix timestamp 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. Fixes: 232e0f6 ("iio: chemical: add support for Sensirion SPS30 sensor") Reported-by: Lars-Peter Clausen <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]> Cc: <[email protected]> Acked-by: Tomasz Duszynski <[email protected]>
1 parent 10134ec commit a5bf6fd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/iio/chemical/sps30.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,18 @@ static irqreturn_t sps30_trigger_handler(int irq, void *p)
230230
struct iio_dev *indio_dev = pf->indio_dev;
231231
struct sps30_state *state = iio_priv(indio_dev);
232232
int ret;
233-
s32 data[4 + 2]; /* PM1, PM2P5, PM4, PM10, timestamp */
233+
struct {
234+
s32 data[4]; /* PM1, PM2P5, PM4, PM10 */
235+
s64 ts;
236+
} scan;
234237

235238
mutex_lock(&state->lock);
236-
ret = sps30_do_meas(state, data, 4);
239+
ret = sps30_do_meas(state, scan.data, ARRAY_SIZE(scan.data));
237240
mutex_unlock(&state->lock);
238241
if (ret)
239242
goto err;
240243

241-
iio_push_to_buffers_with_timestamp(indio_dev, data,
244+
iio_push_to_buffers_with_timestamp(indio_dev, &scan,
242245
iio_get_time_ns(indio_dev));
243246
err:
244247
iio_trigger_notify_done(indio_dev->trig);

0 commit comments

Comments
 (0)