Staging: iio: accel: adis16201: Use GENMASK
authorHimanshu Jha <himanshujha199640@gmail.com>
Thu, 22 Mar 2018 19:12:43 +0000 (00:42 +0530)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 24 Mar 2018 14:20:13 +0000 (14:20 +0000)
Use GENMASK to improve readability and remove the local variables used to
store intermediate data.

Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/staging/iio/accel/adis16201.c

index b04dbb35496cd82a6aa959d3606ef8cb602b070e..f95d1ea8dc17abcee829066692bd82cd7478f1ca 100644 (file)
@@ -185,28 +185,24 @@ static int adis16201_write_raw(struct iio_dev *indio_dev,
                               long mask)
 {
        struct adis *st = iio_priv(indio_dev);
-       int bits;
-       s16 val16;
-       u8 addr;
+       int m;
 
-       switch (mask) {
-       case IIO_CHAN_INFO_CALIBBIAS:
-               switch (chan->type) {
-               case IIO_ACCEL:
-                       bits = 12;
-                       break;
-               case IIO_INCLI:
-                       bits = 9;
-                       break;
-               default:
-                       return -EINVAL;
-               }
-               val16 = val & ((1 << bits) - 1);
-               addr = adis16201_addresses[chan->scan_index];
-               return adis_write_reg_16(st, addr, val16);
+       if (mask != IIO_CHAN_INFO_CALIBBIAS)
+               return -EINVAL;
+
+       switch (chan->type) {
+       case IIO_ACCEL:
+               m = GENMASK(11, 0);
+               break;
+       case IIO_INCLI:
+               m = GENMASK(8, 0);
+               break;
+       default:
+               return -EINVAL;
        }
 
-       return -EINVAL;
+       return adis_write_reg_16(st, adis16201_addresses[chan->scan_index],
+                                val & m);
 }
 
 static const struct iio_chan_spec adis16201_channels[] = {