diff mbox series

[14/19] iio: prox: as3935: Fix buffer alignment in iio_push_to_buffers_with_timestamp()

Message ID 20210501170121.512209-15-jic23@kernel.org (mailing list archive)
State New, archived
Headers show
Series IIO: Alignment fixes part 2 - struct used to ensure alignment | expand

Commit Message

Jonathan Cameron May 1, 2021, 5:01 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

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: 37b1ba2c68cf ("iio: proximity: as3935: fix buffer stack trashing")
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Matt Ranostay <matt.ranostay@konsulko.com>
---
 drivers/iio/proximity/as3935.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Matt Ranostay May 6, 2021, 6:45 a.m. UTC | #1
On Sat, May 1, 2021 at 10:03 AM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> 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: 37b1ba2c68cf ("iio: proximity: as3935: fix buffer stack trashing")
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Acked-by: Matt Ranostay <matt.ranostay@konsulko.com>

> Cc: Matt Ranostay <matt.ranostay@konsulko.com>
> ---
>  drivers/iio/proximity/as3935.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
> index edc4a35ae66d..1d5ace2bde44 100644
> --- a/drivers/iio/proximity/as3935.c
> +++ b/drivers/iio/proximity/as3935.c
> @@ -59,7 +59,11 @@ struct as3935_state {
>         unsigned long noise_tripped;
>         u32 tune_cap;
>         u32 nflwdth_reg;
> -       u8 buffer[16]; /* 8-bit data + 56-bit padding + 64-bit timestamp */
> +       /* Ensure timestamp is naturally aligned */
> +       struct {
> +               u8 chan;
> +               s64 timestamp __aligned(8);
> +       } scan;
>         u8 buf[2] ____cacheline_aligned;
>  };
>
> @@ -225,8 +229,8 @@ static irqreturn_t as3935_trigger_handler(int irq, void *private)
>         if (ret)
>                 goto err_read;
>
> -       st->buffer[0] = val & AS3935_DATA_MASK;
> -       iio_push_to_buffers_with_timestamp(indio_dev, &st->buffer,
> +       st->scan.chan = val & AS3935_DATA_MASK;
> +       iio_push_to_buffers_with_timestamp(indio_dev, &st->scan,
>                                            iio_get_time_ns(indio_dev));
>  err_read:
>         iio_trigger_notify_done(indio_dev->trig);
> --
> 2.31.1
>
diff mbox series

Patch

diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
index edc4a35ae66d..1d5ace2bde44 100644
--- a/drivers/iio/proximity/as3935.c
+++ b/drivers/iio/proximity/as3935.c
@@ -59,7 +59,11 @@  struct as3935_state {
 	unsigned long noise_tripped;
 	u32 tune_cap;
 	u32 nflwdth_reg;
-	u8 buffer[16]; /* 8-bit data + 56-bit padding + 64-bit timestamp */
+	/* Ensure timestamp is naturally aligned */
+	struct {
+		u8 chan;
+		s64 timestamp __aligned(8);
+	} scan;
 	u8 buf[2] ____cacheline_aligned;
 };
 
@@ -225,8 +229,8 @@  static irqreturn_t as3935_trigger_handler(int irq, void *private)
 	if (ret)
 		goto err_read;
 
-	st->buffer[0] = val & AS3935_DATA_MASK;
-	iio_push_to_buffers_with_timestamp(indio_dev, &st->buffer,
+	st->scan.chan = val & AS3935_DATA_MASK;
+	iio_push_to_buffers_with_timestamp(indio_dev, &st->scan,
 					   iio_get_time_ns(indio_dev));
 err_read:
 	iio_trigger_notify_done(indio_dev->trig);