public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jonathan.cameron@huawei.com>
To: Rodrigo Ribeiro <rodrigorsdc@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Michael Hennerich <Michael.Hennerich@analog.com>,
	Stefan Popa <stefan.popa@analog.com>,
	Hartmut Knaack <knaack.h@gmx.de>,
	"Peter Meerwald-Stadler" <pmeerw@pmeerw.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	<linux-iio@vger.kernel.org>, <devel@driverdev.osuosl.org>,
	LKML <linux-kernel@vger.kernel.org>,
	<kernel-usp@googlegroups.com>
Subject: Re: [PATCH] staging: iio: accel: adis16240: Improve readability on write_raw function
Date: Mon, 12 Aug 2019 09:57:17 +0100	[thread overview]
Message-ID: <20190812095717.00002918@huawei.com> (raw)
In-Reply-To: <CAOeBkLqGe-5LwBq1yrX_F8kNn2UK-7+7H+AOZPAqKS5OKHuYkA@mail.gmail.com>

On Sun, 11 Aug 2019 13:47:04 -0300
Rodrigo Ribeiro <rodrigorsdc@gmail.com> wrote:

> Em dom, 11 de ago de 2019 às 05:43, Jonathan Cameron
> <jic23@kernel.org> escreveu:
> >
> > On Sat, 10 Aug 2019 12:00:58 -0300
> > Rodrigo <rodrigorsdc@gmail.com> wrote:
> >  
> > > From: Rodrigo Carvalho <rodrigorsdc@gmail.com>
> > >
> > > Improve readability by using GENMASK macro, changing switch statement
> > > by if statement and removing unnecessary local variables.  
> >  
> 
> Hi Jonathan. Thanks for reviewing!
> 
> > From your description it sounds like multiple changes in one patch.
> > Always preferable to have one type of change in a patch and more
> > small patches.
> >
> > Based on comments below, I would leave the switch statement alone,
> > but put in your GENMASK change as that one is good and gets
> > rid of the odd local variable 'bits' as well :)
> >
> > Thanks,
> >
> > Jonathan
> >
> >  
> > >
> > > Signed-off-by: Rodrigo Ribeiro Carvalho <rodrigorsdc@gmail.com>
> > > ---
> > >  drivers/staging/iio/accel/adis16240.c | 16 +++++++---------
> > >  1 file changed, 7 insertions(+), 9 deletions(-)
> > >
> > > diff --git a/drivers/staging/iio/accel/adis16240.c b/drivers/staging/iio/accel/adis16240.c
> > > index 62f4b3b1b457..68f165501389 100644
> > > --- a/drivers/staging/iio/accel/adis16240.c
> > > +++ b/drivers/staging/iio/accel/adis16240.c
> > > @@ -309,17 +309,15 @@ static int adis16240_write_raw(struct iio_dev *indio_dev,
> > >                              long mask)
> > >  {
> > >       struct adis *st = iio_priv(indio_dev);
> > > -     int bits = 10;
> > > -     s16 val16;
> > > +     int m;
> > >       u8 addr;
> > >
> > > -     switch (mask) {
> > > -     case IIO_CHAN_INFO_CALIBBIAS:
> > > -             val16 = val & ((1 << bits) - 1);
> > > -             addr = adis16240_addresses[chan->scan_index][0];
> > > -             return adis_write_reg_16(st, addr, val16);
> > > -     }
> > > -     return -EINVAL;
> > > +     if (mask != IIO_CHAN_INFO_CALIBBIAS)
> > > +             return -EINVAL;  
> >
> > Hmm. We generally encourage the use of switch statements in these
> > cases because they reduce churn as new features are added.
> >
> > In this particular case, we don't have any control of sampling frequency
> > in the driver, but the hardware appears to support it (table 23 on the
> > datasheet).  
> 
> On drivers of same kind out of staging (adis16209 and adis16201), sampling
> frequency writing are not implemented, even though datasheets suggest a register
> writing for this. I can try to implement if it is a good one.

I would be a bit nervous about doing so if you don't have
hardware, and we can't find anyone who is setup to test the device.

Obviously if you can get it tested one way or the other, it would be good
to add support.


Thanks,

J

> 
> > > +
> > > +     m = GENMASK(9, 0);
> > > +     addr = adis16240_addresses[chan->scan_index][0];
> > > +     return adis_write_reg_16(st, addr, val & m);  
> > Why the local variable m?  Can we not just do
> >
> >         return adis_write_reg_16(st, addr, val & GENMASK(9, 0));
> >
> > If anything I think that is a little more readable than your
> > version.  There is a reasonable argument for just having
> > addr inline as well.
> >
> >         return adis_write_reg_16(st,
> >                                  adis16240_addresses[chan->scan_index][0],
> >                                  val & GENMASK(9, 0));
> >
> > However, given I'm suggesting you leave it as a switch statement, it
> > will be too long with addr inline.
> >  
> > >  }
> > >
> > >  static const struct iio_chan_spec adis16240_channels[] = {  
> >  
> 
> Regards,
> Rodrigo



      reply	other threads:[~2019-08-12  8:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-10 15:00 [PATCH] staging: iio: accel: adis16240: Improve readability on write_raw function Rodrigo
2019-08-11  8:43 ` Jonathan Cameron
2019-08-11 16:47   ` Rodrigo Ribeiro
2019-08-12  8:57     ` Jonathan Cameron [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190812095717.00002918@huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jic23@kernel.org \
    --cc=kernel-usp@googlegroups.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=rodrigorsdc@gmail.com \
    --cc=stefan.popa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox