]> git.baikalelectronics.ru Git - kernel.git/commitdiff
iio: pressure: hp206c: Use get_unaligned_be24()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 21 Apr 2020 00:31:31 +0000 (03:31 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 3 May 2020 08:47:20 +0000 (09:47 +0100)
This makes the driver code slightly easier to read.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/pressure/hp206c.c

index 3ac3632e7242bada770936070bd42a425b968da6..1f931f5b7a65061283dc54b57f7bcdf70de29f6c 100644 (file)
@@ -18,6 +18,8 @@
 #include <linux/util_macros.h>
 #include <linux/acpi.h>
 
+#include <asm/unaligned.h>
+
 /* I2C commands: */
 #define HP206C_CMD_SOFT_RST    0x06
 
@@ -93,12 +95,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. */