iio:chemical:sps30: Fix timestamp alignment
authorJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 17 May 2020 17:29:59 +0000 (18:29 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Fri, 22 May 2020 16:30:55 +0000 (17:30 +0100)
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: 232e0f6ddeae ("iio: chemical: add support for Sensirion SPS30 sensor")
Reported-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: <Stable@vger.kernel.org>
Acked-by: Tomasz Duszynski <tomasz.duszynski@octakon.com>
drivers/iio/chemical/sps30.c

index acb9f8ecbb3da1c3684b3e95cdb8c265820b25b1..a88c1fb875a04c79b2b6e7f4d21c8200a661f7eb 100644 (file)
@@ -230,15 +230,18 @@ static irqreturn_t sps30_trigger_handler(int irq, void *p)
        struct iio_dev *indio_dev = pf->indio_dev;
        struct sps30_state *state = iio_priv(indio_dev);
        int ret;
-       s32 data[4 + 2]; /* PM1, PM2P5, PM4, PM10, timestamp */
+       struct {
+               s32 data[4]; /* PM1, PM2P5, PM4, PM10 */
+               s64 ts;
+       } scan;
 
        mutex_lock(&state->lock);
-       ret = sps30_do_meas(state, data, 4);
+       ret = sps30_do_meas(state, scan.data, ARRAY_SIZE(scan.data));
        mutex_unlock(&state->lock);
        if (ret)
                goto err;
 
-       iio_push_to_buffers_with_timestamp(indio_dev, data,
+       iio_push_to_buffers_with_timestamp(indio_dev, &scan,
                                           iio_get_time_ns(indio_dev));
 err:
        iio_trigger_notify_done(indio_dev->trig);