Re: [PATCH 01/19] iio: accel: bma180: Fix buffer alignment in iio_push_to_buffers_with_timestamp()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat,  1 May 2021 18:01:03 +0100
Jonathan Cameron <jic23@xxxxxxxxxx> wrote:

> From: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
> 
> 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: b9a6a237ffc9 ("iio:bma180: Drop _update_scan_mode()")
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
> Cc: Peter Meerwald <pmeerw@xxxxxxxxxx>

Applied to the togreg branch of iio.git with a minor fix.

Note I'm taking these the slow way and nor marking them for stable
as they've been there a very long time.

> ---
>  drivers/iio/accel/bma180.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
> index b8a7469cdae4..2e901f900ea7 100644
> --- a/drivers/iio/accel/bma180.c
> +++ b/drivers/iio/accel/bma180.c
> @@ -162,7 +162,11 @@ struct bma180_data {
>  	int scale;
>  	int bw;
>  	bool pmode;
> -	u8 buff[16]; /* 3x 16-bit + 8-bit + padding + timestamp */
> +	/* Ensure timestamp is naturally aligned */
> +	struct {
> +		s16 chan[3];
The 8 bit in the comment above is misleading, but made me take another
look at this.   There are actually 4 channels on some devices, the last
of which (temp) is 8 bits in a 16bit field. 

I changed this to be s16 chan[4] to reflect that.

Thanks,

Jonathan

> +		s64 timestamp __aligned(8);
> +	} scan;
>  };
>  
>  enum bma180_chan {
> @@ -938,12 +942,12 @@ static irqreturn_t bma180_trigger_handler(int irq, void *p)
>  			mutex_unlock(&data->mutex);
>  			goto err;
>  		}
> -		((s16 *)data->buff)[i++] = ret;
> +		data->scan.chan[i++] = ret;
>  	}
>  
>  	mutex_unlock(&data->mutex);
>  
> -	iio_push_to_buffers_with_timestamp(indio_dev, data->buff, time_ns);
> +	iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, time_ns);
>  err:
>  	iio_trigger_notify_done(indio_dev->trig);
>  




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux