lkml.org 
[lkml]   [2019]   [May]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
SubjectRe: [PATCH 2/4] staging: iio: ad7150: use FIELD_GET and GENMASK
Date
On Sat, 2019-05-04 at 13:43 +0300, Alexandru Ardelean wrote:
> [External]
>
>
> On Sat, May 4, 2019 at 1:25 AM Melissa Wen <melissa.srw@gmail.com> wrote:
> >
> > Use the bitfield macro FIELD_GET, and GENMASK to do the shift and mask
> > in
> > one go. This makes the code more readable than explicit masking
> > followed
> > by a shift.
> >
>
> This looks neat.
> I'd have to remember to ack it from my work email.

Acked-by: Alexandru Ardelean <alexandru.ardelean@analog.com>

>
> One minor comment inline, which would be the object of a new patch.
>
> > Signed-off-by: Melissa Wen <melissa.srw@gmail.com>
> > ---
> > drivers/staging/iio/cdc/ad7150.c | 6 +++++-
> > 1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/iio/cdc/ad7150.c
> > b/drivers/staging/iio/cdc/ad7150.c
> > index 24601ba7db88..4ba46fb6ac02 100644
> > --- a/drivers/staging/iio/cdc/ad7150.c
> > +++ b/drivers/staging/iio/cdc/ad7150.c
> > @@ -5,6 +5,7 @@
> > * Copyright 2010-2011 Analog Devices Inc.
> > */
> >
> > +#include <linux/bitfield.h>
> > #include <linux/interrupt.h>
> > #include <linux/device.h>
> > #include <linux/kernel.h>
> > @@ -44,6 +45,9 @@
> > #define AD7150_SN0_REG 0x16
> > #define AD7150_ID_REG 0x17
> >
> > +/* AD7150 masks */
> > +#define AD7150_THRESHTYPE_MSK GENMASK(6, 5)
> > +
> > /**
> > * struct ad7150_chip_info - instance specific chip data
> > * @client: i2c client for this device
> > @@ -136,7 +140,7 @@ static int ad7150_read_event_config(struct iio_dev
> > *indio_dev,
> > if (ret < 0)
> > return ret;
> >
> > - threshtype = (ret >> 5) & 0x03;
> > + threshtype = FIELD_GET(AD7150_THRESHTYPE_MSK, ret);
> > adaptive = !!(ret & 0x80);
>
> Why not also do something similar for the `adaptive` value ?
>
> >
> > switch (type) {
> > --
> > 2.20.1
> >
\
 
 \ /
  Last update: 2019-05-06 08:51    [W:0.160 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site