Re: [PATCH 16/19] iio: magn: bmc150: 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:18 +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 uses of
> iio_push_to_buffers_with_timestamp()
> 
> Fixes: c91746a2361d ("iio: magn: Add support for BMC150 magnetometer")
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
> Cc: Stephan Gerhold <stephan@xxxxxxxxxxx>
> Cc: Linus Walleij <linus.walleij@xxxxxxxxxx>

Applied, but with a tiny tweak to make this more obviously correct.

> ---
>  drivers/iio/magnetometer/bmc150_magn.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c
> index 00f9766bad5c..dd5f80093a18 100644
> --- a/drivers/iio/magnetometer/bmc150_magn.c
> +++ b/drivers/iio/magnetometer/bmc150_magn.c
> @@ -138,8 +138,11 @@ struct bmc150_magn_data {
>  	struct regmap *regmap;
>  	struct regulator_bulk_data regulators[2];
>  	struct iio_mount_matrix orientation;
> -	/* 4 x 32 bits for x, y z, 4 bytes align, 64 bits timestamp */
> -	s32 buffer[6];
> +	/* Ensure timestamp is naturally aligned */
> +	struct {
> +		s32 chans[4];
The whole point of the structure is to enforce the alignment without needing
to specify padding.   There are only 3 actual chans, so I've reduced this to
s32 chans[3]

Result is exactly the same in practice, but it's more readable.

Thanks,

Jonathan

> +		s64 timestamp __aligned(8);
> +	} scan;
>  	struct iio_trigger *dready_trig;
>  	bool dready_trigger_on;
>  	int max_odr;
> @@ -675,11 +678,11 @@ static irqreturn_t bmc150_magn_trigger_handler(int irq, void *p)
>  	int ret;
>  
>  	mutex_lock(&data->mutex);
> -	ret = bmc150_magn_read_xyz(data, data->buffer);
> +	ret = bmc150_magn_read_xyz(data, data->scan.chans);
>  	if (ret < 0)
>  		goto err;
>  
> -	iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
> +	iio_push_to_buffers_with_timestamp(indio_dev, &data->scan,
>  					   pf->timestamp);
>  
>  err:




[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