diff mbox series

[03/17] staging: iio: cdc: ad7746: Use explicit be24 handling.

Message ID 20220418192907.763933-4-jic23@kernel.org (mailing list archive)
State Superseded
Headers show
Series staging/iio: Clean up AD7746 CDC driver and move from staging. | expand

Commit Message

Jonathan Cameron April 18, 2022, 7:28 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Change from fiddly local implementation of be24 to cpu endian conversion
by reading into a 3 byte buffer and using get_unaligned_be24()

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/staging/iio/cdc/ad7746.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Andy Shevchenko April 26, 2022, 10:58 a.m. UTC | #1
On Wed, Apr 20, 2022 at 11:23 AM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Change from fiddly local implementation of be24 to cpu endian conversion
> by reading into a 3 byte buffer and using get_unaligned_be24()
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/staging/iio/cdc/ad7746.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c
> index 71c709771676..1f510610ed32 100644
> --- a/drivers/staging/iio/cdc/ad7746.c
> +++ b/drivers/staging/iio/cdc/ad7746.c
> @@ -95,10 +95,7 @@ struct ad7746_chip_info {
>         u8      capdac[2][2];
>         s8      capdac_set;
>
> -       union {
> -               __be32 d32;
> -               u8 d8[4];
> -       } data ____cacheline_aligned;
> +       u8 data[3] ____cacheline_aligned;
>  };
>
>  enum ad7746_chan {
> @@ -547,12 +544,12 @@ static int ad7746_read_raw(struct iio_dev *indio_dev,
>
>                 ret = i2c_smbus_read_i2c_block_data(chip->client,
>                                                     chan->address >> 8, 3,

At the same time it makes now sense to use sizeof() here.

> -                                                   &chip->data.d8[1]);
> +                                                   chip->data);
>
>                 if (ret < 0)
>                         goto out;
>
> -               *val = (be32_to_cpu(chip->data.d32) & 0xFFFFFF) - 0x800000;
> +               *val = get_unaligned_be24(chip->data) - 0x800000;
>
>                 switch (chan->type) {
>                 case IIO_TEMP:
> --
> 2.35.3
>
diff mbox series

Patch

diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c
index 71c709771676..1f510610ed32 100644
--- a/drivers/staging/iio/cdc/ad7746.c
+++ b/drivers/staging/iio/cdc/ad7746.c
@@ -95,10 +95,7 @@  struct ad7746_chip_info {
 	u8	capdac[2][2];
 	s8	capdac_set;
 
-	union {
-		__be32 d32;
-		u8 d8[4];
-	} data ____cacheline_aligned;
+	u8 data[3] ____cacheline_aligned;
 };
 
 enum ad7746_chan {
@@ -547,12 +544,12 @@  static int ad7746_read_raw(struct iio_dev *indio_dev,
 
 		ret = i2c_smbus_read_i2c_block_data(chip->client,
 						    chan->address >> 8, 3,
-						    &chip->data.d8[1]);
+						    chip->data);
 
 		if (ret < 0)
 			goto out;
 
-		*val = (be32_to_cpu(chip->data.d32) & 0xFFFFFF) - 0x800000;
+		*val = get_unaligned_be24(chip->data) - 0x800000;
 
 		switch (chan->type) {
 		case IIO_TEMP: