Message ID | 1521745965-26972-2-git-send-email-himanshujha199640@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Fri, 23 Mar 2018 00:42:43 +0530 Himanshu Jha <himanshujha199640@gmail.com> wrote: > Use GENMASK to improve readability and remove the local variables used to > store intermediate data. > > Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com> Applied to the togreg branch of iio.git. Thanks, Jonathan > --- > drivers/staging/iio/accel/adis16201.c | 34 +++++++++++++++------------------- > 1 file changed, 15 insertions(+), 19 deletions(-) > > diff --git a/drivers/staging/iio/accel/adis16201.c b/drivers/staging/iio/accel/adis16201.c > index b04dbb3..e7593fa 100644 > --- a/drivers/staging/iio/accel/adis16201.c > +++ b/drivers/staging/iio/accel/adis16201.c > @@ -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; > + 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; > } > - val16 = val & ((1 << bits) - 1); > - addr = adis16201_addresses[chan->scan_index]; > - return adis_write_reg_16(st, addr, val16); > - } > > - return -EINVAL; > + return adis_write_reg_16(st, adis16201_addresses[chan->scan_index], > + val & m); > } > > static const struct iio_chan_spec adis16201_channels[] = { -- To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/staging/iio/accel/adis16201.c b/drivers/staging/iio/accel/adis16201.c index b04dbb3..e7593fa 100644 --- a/drivers/staging/iio/accel/adis16201.c +++ b/drivers/staging/iio/accel/adis16201.c @@ -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; + 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; } - val16 = val & ((1 << bits) - 1); - addr = adis16201_addresses[chan->scan_index]; - return adis_write_reg_16(st, addr, val16); - } - return -EINVAL; + return adis_write_reg_16(st, adis16201_addresses[chan->scan_index], + val & m); } static const struct iio_chan_spec adis16201_channels[] = {
Use GENMASK to improve readability and remove the local variables used to store intermediate data. Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com> --- drivers/staging/iio/accel/adis16201.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-)