diff mbox series

[v1,12/16] iio: pressure: hp206c: Use get_unaligned_be24()

Message ID 20200421003135.23060-12-andriy.shevchenko@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [v1,01/16] iio: adc: ad_sigma_delta: Use {get,put}_unaligned_be24() | expand

Commit Message

Andy Shevchenko April 21, 2020, 12:31 a.m. UTC
This makes the driver code slightly easier to read.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/pressure/hp206c.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Jonathan Cameron April 25, 2020, 4:45 p.m. UTC | #1
On Tue, 21 Apr 2020 03:31:31 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> This makes the driver code slightly easier to read.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Applied with header added.

Jonathan

> ---
>  drivers/iio/pressure/hp206c.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/pressure/hp206c.c b/drivers/iio/pressure/hp206c.c
> index 3ac3632e7242..d746882eccc8 100644
> --- a/drivers/iio/pressure/hp206c.c
> +++ b/drivers/iio/pressure/hp206c.c
> @@ -93,12 +93,12 @@ static int hp206c_read_20bit(struct i2c_client *client, u8 cmd)
>  	int ret;
>  	u8 values[3];
>  
> -	ret = i2c_smbus_read_i2c_block_data(client, cmd, 3, values);
> +	ret = i2c_smbus_read_i2c_block_data(client, cmd, sizeof(values), values);
>  	if (ret < 0)
>  		return ret;
> -	if (ret != 3)
> +	if (ret != sizeof(values))
>  		return -EIO;
> -	return ((values[0] & 0xF) << 16) | (values[1] << 8) | (values[2]);
> +	return get_unaligned_be24(&values[0]) & GENMASK(19, 0);
>  }
>  
>  /* Spin for max 160ms until DEV_RDY is 1, or return error. */
diff mbox series

Patch

diff --git a/drivers/iio/pressure/hp206c.c b/drivers/iio/pressure/hp206c.c
index 3ac3632e7242..d746882eccc8 100644
--- a/drivers/iio/pressure/hp206c.c
+++ b/drivers/iio/pressure/hp206c.c
@@ -93,12 +93,12 @@  static int hp206c_read_20bit(struct i2c_client *client, u8 cmd)
 	int ret;
 	u8 values[3];
 
-	ret = i2c_smbus_read_i2c_block_data(client, cmd, 3, values);
+	ret = i2c_smbus_read_i2c_block_data(client, cmd, sizeof(values), values);
 	if (ret < 0)
 		return ret;
-	if (ret != 3)
+	if (ret != sizeof(values))
 		return -EIO;
-	return ((values[0] & 0xF) << 16) | (values[1] << 8) | (values[2]);
+	return get_unaligned_be24(&values[0]) & GENMASK(19, 0);
 }
 
 /* Spin for max 160ms until DEV_RDY is 1, or return error. */