linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matt Ranostay <matt.ranostay@konsulko.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "open list:IIO SUBSYSTEM AND DRIVERS" <linux-iio@vger.kernel.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: Re: [PATCH 14/19] iio: prox: as3935: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
Date: Wed, 5 May 2021 23:45:42 -0700	[thread overview]
Message-ID: <CAJCx=gkE+UQLdkY5=Ead+6cJcJTrf2m1oO_7L6MJ4f8G5=haKw@mail.gmail.com> (raw)
In-Reply-To: <20210501170121.512209-15-jic23@kernel.org>

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
>

  reply	other threads:[~2021-05-06  6:45 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-01 17:01 [PATCH 00/19] IIO: Alignment fixes part 2 - struct used to ensure alignment Jonathan Cameron
2021-05-01 17:01 ` [PATCH 01/19] iio: accel: bma180: Fix buffer alignment in iio_push_to_buffers_with_timestamp() Jonathan Cameron
2021-05-13 17:22   ` Jonathan Cameron
2021-05-01 17:01 ` [PATCH 02/19] iio: accel: bma220: " Jonathan Cameron
2021-05-13 17:26   ` Jonathan Cameron
2021-05-01 17:01 ` [PATCH 03/19] iio: accel: hid: " Jonathan Cameron
2021-05-13 17:28   ` Jonathan Cameron
2021-05-01 17:01 ` [PATCH 04/19] iio: accel: kxcjk-1013: " Jonathan Cameron
2021-05-01 19:10   ` Andy Shevchenko
2021-05-13 17:33     ` Jonathan Cameron
2021-05-01 17:01 ` [PATCH 05/19] iio: accel: mxc4005: Fix overread of data and alignment issue Jonathan Cameron
2021-05-13 17:37   ` Jonathan Cameron
2021-05-01 17:01 ` [PATCH 06/19] iio: accel: stk8312: Fix buffer alignment in iio_push_to_buffers_with_timestamp() Jonathan Cameron
2021-05-13 17:39   ` Jonathan Cameron
2021-05-01 17:01 ` [PATCH 07/19] iio: accel: stk8ba50: " Jonathan Cameron
2021-05-01 17:01 ` [PATCH 08/19] iio: adc: ti-ads1015: " Jonathan Cameron
2021-05-01 17:01 ` [PATCH 09/19] iio: adc: vf610: " Jonathan Cameron
2021-05-01 17:01 ` [PATCH 10/19] iio: gyro: bmg160: " Jonathan Cameron
2021-05-01 17:01 ` [PATCH 11/19] iio: humidity: am2315: " Jonathan Cameron
2021-05-01 17:01 ` [PATCH 12/19] iio: prox: srf08: " Jonathan Cameron
2021-05-01 17:01 ` [PATCH 13/19] iio: prox: pulsed-light: " Jonathan Cameron
2021-05-06  6:46   ` Matt Ranostay
2021-05-01 17:01 ` [PATCH 14/19] iio: prox: as3935: " Jonathan Cameron
2021-05-06  6:45   ` Matt Ranostay [this message]
2021-05-01 17:01 ` [PATCH 15/19] iio: magn: hmc5843: " Jonathan Cameron
2021-05-01 17:01 ` [PATCH 16/19] iio: magn: bmc150: " Jonathan Cameron
2021-05-05 12:57   ` Linus Walleij
2021-05-07  9:23     ` Jonathan Cameron
2021-05-13 17:50   ` Jonathan Cameron
2021-05-01 17:01 ` [PATCH 17/19] iio: light: isl29125: " Jonathan Cameron
2021-05-01 17:01 ` [PATCH 18/19] iio: light: tcs3414: " Jonathan Cameron
2021-05-01 17:01 ` [PATCH 19/19] iio: light: tcs3472: " Jonathan Cameron
2021-05-01 19:09   ` Andy Shevchenko
2021-05-01 19:12 ` [PATCH 00/19] IIO: Alignment fixes part 2 - struct used to ensure alignment Andy Shevchenko
2021-05-13 17:54   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJCx=gkE+UQLdkY5=Ead+6cJcJTrf2m1oO_7L6MJ4f8G5=haKw@mail.gmail.com' \
    --to=matt.ranostay@konsulko.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --subject='Re: [PATCH 14/19] iio: prox: as3935: Fix buffer alignment in iio_push_to_buffers_with_timestamp()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox