summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Cameron <Jonathan.Cameron@huawei.com>2021-05-01 18:01:10 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-07-20 16:15:54 +0200
commitb0d27f41be7bd2b9ffd775cec91aff906bfbfcb8 (patch)
tree1f6cdf8b0c892017b34e7ae8054cd1d619f49c6d
parent3ffec10f9bd0c91a3c5dbbe2ad3b371c8013dfd3 (diff)
downloadlinux-stable-b0d27f41be7bd2b9ffd775cec91aff906bfbfcb8.tar.gz
linux-stable-b0d27f41be7bd2b9ffd775cec91aff906bfbfcb8.tar.bz2
linux-stable-b0d27f41be7bd2b9ffd775cec91aff906bfbfcb8.zip
iio: adc: ti-ads1015: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
[ Upstream commit d85d71dd1ab67eaa7351f69fec512d8f09d164e1 ] 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 this function. Fixes: ecc24e72f437 ("iio: adc: Add TI ADS1015 ADC driver support") Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Cc: Daniel Baluta <daniel.baluta@nxp.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20210501170121.512209-9-jic23@kernel.org Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/iio/adc/ti-ads1015.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index dc8d859e4b92..b1cccc3eeea6 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -391,10 +391,14 @@ static irqreturn_t ads1015_trigger_handler(int irq, void *p)
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->indio_dev;
struct ads1015_data *data = iio_priv(indio_dev);
- s16 buf[8]; /* 1x s16 ADC val + 3x s16 padding + 4x s16 timestamp */
+ /* Ensure natural alignment of timestamp */
+ struct {
+ s16 chan;
+ s64 timestamp __aligned(8);
+ } scan;
int chan, ret, res;
- memset(buf, 0, sizeof(buf));
+ memset(&scan, 0, sizeof(scan));
mutex_lock(&data->lock);
chan = find_first_bit(indio_dev->active_scan_mask,
@@ -405,10 +409,10 @@ static irqreturn_t ads1015_trigger_handler(int irq, void *p)
goto err;
}
- buf[0] = res;
+ scan.chan = res;
mutex_unlock(&data->lock);
- iio_push_to_buffers_with_timestamp(indio_dev, buf,
+ iio_push_to_buffers_with_timestamp(indio_dev, &scan,
iio_get_time_ns(indio_dev));
err: