Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: light: tcs3472: Fix buffer alignment in iio_push_to_buffers_with_timestamp()

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 tag is not strictly accurate as prior to that patch there was
potentially an unaligned write. However, any backport past there will
need to be done manually.

Fixes: 0624bf847dd0 ("iio:tcs3472: Use iio_push_to_buffers_with_timestamp()")
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-20-jic23@kernel.org

+7 -3
+7 -3
drivers/iio/light/tcs3472.c
··· 64 64 u8 control; 65 65 u8 atime; 66 66 u8 apers; 67 - u16 buffer[8]; /* 4 16-bit channels + 64-bit timestamp */ 67 + /* Ensure timestamp is naturally aligned */ 68 + struct { 69 + u16 chans[4]; 70 + s64 timestamp __aligned(8); 71 + } scan; 68 72 }; 69 73 70 74 static const struct iio_event_spec tcs3472_events[] = { ··· 390 386 if (ret < 0) 391 387 goto done; 392 388 393 - data->buffer[j++] = ret; 389 + data->scan.chans[j++] = ret; 394 390 } 395 391 396 - iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 392 + iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, 397 393 iio_get_time_ns(indio_dev)); 398 394 399 395 done: