[PATCH 09/10] iio: adc: ti-ads8688: use struct with aligned_s64 timestamp
David Lechner
dlechner at baylibre.com
Fri Apr 18 12:58:28 PDT 2025
Use a struct with aligned s64_timestamp instead of a padded array for
the buffer used for iio_push_to_buffers_with_ts(). This makes it easier
to see the correctness of the size and alignment of the buffer.
Changed from struct initializer to memset() in case the size ever
changes and there could be holes in the struct. The compiler generally
optimizes calls to memset() anyway.
Signed-off-by: David Lechner <dlechner at baylibre.com>
---
drivers/iio/adc/ti-ads8688.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/adc/ti-ads8688.c b/drivers/iio/adc/ti-ads8688.c
index b0bf46cae0b69eb1fe8d7734c8a32ac642c5d0cd..2a9cb7d9bbfae4b282682d755992acd47fb88b99 100644
--- a/drivers/iio/adc/ti-ads8688.c
+++ b/drivers/iio/adc/ti-ads8688.c
@@ -380,16 +380,20 @@ static irqreturn_t ads8688_trigger_handler(int irq, void *p)
{
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->indio_dev;
- /* Ensure naturally aligned timestamp */
- u16 buffer[ADS8688_MAX_CHANNELS + sizeof(s64)/sizeof(u16)] __aligned(8) = { };
+ struct {
+ u16 data[ADS8688_MAX_CHANNELS];
+ aligned_s64 timestamp;
+ } buffer;
int i, j = 0;
+ memset(&buffer, 0, sizeof(buffer));
+
iio_for_each_active_channel(indio_dev, i) {
- buffer[j] = ads8688_read(indio_dev, i);
+ buffer.data[j] = ads8688_read(indio_dev, i);
j++;
}
- iio_push_to_buffers_with_ts(indio_dev, buffer, sizeof(buffer),
+ iio_push_to_buffers_with_ts(indio_dev, &buffer, sizeof(buffer),
iio_get_time_ns(indio_dev));
iio_trigger_notify_done(indio_dev->trig);
--
2.43.0
More information about the linux-arm-kernel
mailing list