All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: devel@driverdev.osuosl.org, lars@metafoo.de,
	Michael.Hennerich@analog.com, linux-iio@vger.kernel.org,
	gregkh@linuxfoundation.org, 21cnbao@gmail.com,
	linux-kernel@vger.kernel.org,
	Himanshu Jha <himanshujha199640@gmail.com>,
	pmeerw@pmeerw.net, knaack.h@gmx.de
Subject: Re: [PATCH 3/4] staging: iio: accel: Use sign_extend32 and adjust a switch statement
Date: Sat, 17 Feb 2018 20:24:41 +0300	[thread overview]
Message-ID: <20180217172441.2nl632jc3u6himnd@mwanda> (raw)
In-Reply-To: <20180217122353.7ee9bf96@archlinux>

On Sat, Feb 17, 2018 at 12:23:53PM +0000, Jonathan Cameron wrote:
> On Mon, 12 Feb 2018 16:10:01 +0300
> Dan Carpenter <dan.carpenter@oracle.com> wrote:
> 
> > On Mon, Feb 12, 2018 at 05:24:58PM +0530, Himanshu Jha wrote:
> > > Use sign_extend32 function instead of manually coding it. Also, adjust a  
> >                                                             ^^^^^
> > > switch block to explicitly match channels and return -EINVAL as default
> > > case which improves code readability.  
> > 
> > Greg likes to say something along the lines of "when you start your
> > sentence with "Also, " that could be a clue that it should be a separate
> > patch.".
> > 
> > > 
> > > Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
> > > ---
> > >  drivers/staging/iio/accel/adis16201.c | 13 ++++++++-----
> > >  1 file changed, 8 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/drivers/staging/iio/accel/adis16201.c b/drivers/staging/iio/accel/adis16201.c
> > > index 011d2c5..6800347 100644
> > > --- a/drivers/staging/iio/accel/adis16201.c
> > > +++ b/drivers/staging/iio/accel/adis16201.c
> > > @@ -112,12 +112,17 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
> > >  	case IIO_CHAN_INFO_SCALE:
> > >  		switch (chan->type) {
> > >  		case IIO_VOLTAGE:
> > > -			if (chan->channel == 0) {
> > > +			switch (chan->channel) {
> > > +			case 0:
> > >  				*val = 1;
> > >  				*val2 = 220000;
> > > -			} else {
> > > +				break;
> > > +			case 1:
> > >  				*val = 0;
> > >  				*val2 = 610000;
> > > +				break;
> > > +			default:
> > > +				return -EINVAL;
> > >  			}  
> > 
> > I don't think this improves readability.  The -EINVAL is to handle a
> > driver bug which we haven't introduced yet.  Probably we would be better
> > off printing a warning or something?  But it feels weird to introduce so
> > much code to handle a bug which would actually be pretty difficult to
> > write.  The original code is fine.
> 
> Hmm. My thought here was that it is not obvious from the code
> that we only have channel 0 and channel 1.  The if statement
> kind of implies that channel 0 is special compared to 'all the other'
> elements where as what we are actually doing is picking from
> a set of options. So semantically it's a switch statement being
> implemented as an if else pair ;)
> 
> Perhaps we can compromise on the addition of a comment on the else
> case to say it only applies to channel 1?
> 
> Dan, what do you think?
> 
> It isn't particularly important either way though so feel free to
> just drop this one.
> 

To be honest, I dont care either way...  The original and the new code
are equivalently clean to me so I have a "leave the code as-is bias" but
if someone else is invested in this code then I like to let the person
who cares the most be the one to decide.

This patch is actually fine but the patch description makes it sound
like it's doing two things.  If the subject was
"cleanup adis16201_read_raw()" then that would sound like one thing.
I obviously review thousands of staging patches so some of my responses
are pretty mechanical at this point.  If it's a two random things from
the same file then split it into to two patches, but if it's from the
same function that's acceptable.

regards,
dan carpenter


_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Himanshu Jha <himanshujha199640@gmail.com>,
	21cnbao@gmail.com, devel@driverdev.osuosl.org, lars@metafoo.de,
	Michael.Hennerich@analog.com, linux-iio@vger.kernel.org,
	gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	pmeerw@pmeerw.net, knaack.h@gmx.de
Subject: Re: [PATCH 3/4] staging: iio: accel: Use sign_extend32 and adjust a switch statement
Date: Sat, 17 Feb 2018 20:24:41 +0300	[thread overview]
Message-ID: <20180217172441.2nl632jc3u6himnd@mwanda> (raw)
In-Reply-To: <20180217122353.7ee9bf96@archlinux>

On Sat, Feb 17, 2018 at 12:23:53PM +0000, Jonathan Cameron wrote:
> On Mon, 12 Feb 2018 16:10:01 +0300
> Dan Carpenter <dan.carpenter@oracle.com> wrote:
> 
> > On Mon, Feb 12, 2018 at 05:24:58PM +0530, Himanshu Jha wrote:
> > > Use sign_extend32 function instead of manually coding it. Also, adjust a  
> >                                                             ^^^^^
> > > switch block to explicitly match channels and return -EINVAL as default
> > > case which improves code readability.  
> > 
> > Greg likes to say something along the lines of "when you start your
> > sentence with "Also, " that could be a clue that it should be a separate
> > patch.".
> > 
> > > 
> > > Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
> > > ---
> > >  drivers/staging/iio/accel/adis16201.c | 13 ++++++++-----
> > >  1 file changed, 8 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/drivers/staging/iio/accel/adis16201.c b/drivers/staging/iio/accel/adis16201.c
> > > index 011d2c5..6800347 100644
> > > --- a/drivers/staging/iio/accel/adis16201.c
> > > +++ b/drivers/staging/iio/accel/adis16201.c
> > > @@ -112,12 +112,17 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
> > >  	case IIO_CHAN_INFO_SCALE:
> > >  		switch (chan->type) {
> > >  		case IIO_VOLTAGE:
> > > -			if (chan->channel == 0) {
> > > +			switch (chan->channel) {
> > > +			case 0:
> > >  				*val = 1;
> > >  				*val2 = 220000;
> > > -			} else {
> > > +				break;
> > > +			case 1:
> > >  				*val = 0;
> > >  				*val2 = 610000;
> > > +				break;
> > > +			default:
> > > +				return -EINVAL;
> > >  			}  
> > 
> > I don't think this improves readability.  The -EINVAL is to handle a
> > driver bug which we haven't introduced yet.  Probably we would be better
> > off printing a warning or something?  But it feels weird to introduce so
> > much code to handle a bug which would actually be pretty difficult to
> > write.  The original code is fine.
> 
> Hmm. My thought here was that it is not obvious from the code
> that we only have channel 0 and channel 1.  The if statement
> kind of implies that channel 0 is special compared to 'all the other'
> elements where as what we are actually doing is picking from
> a set of options. So semantically it's a switch statement being
> implemented as an if else pair ;)
> 
> Perhaps we can compromise on the addition of a comment on the else
> case to say it only applies to channel 1?
> 
> Dan, what do you think?
> 
> It isn't particularly important either way though so feel free to
> just drop this one.
> 

To be honest, I dont care either way...  The original and the new code
are equivalently clean to me so I have a "leave the code as-is bias" but
if someone else is invested in this code then I like to let the person
who cares the most be the one to decide.

This patch is actually fine but the patch description makes it sound
like it's doing two things.  If the subject was
"cleanup adis16201_read_raw()" then that would sound like one thing.
I obviously review thousands of staging patches so some of my responses
are pretty mechanical at this point.  If it's a two random things from
the same file then split it into to two patches, but if it's from the
same function that's acceptable.

regards,
dan carpenter

  reply	other threads:[~2018-02-17 17:24 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-12 11:54 [PATCH 0/4] staging: iio: accel: adis16201 driver cleanup Himanshu Jha
2018-02-12 11:54 ` Himanshu Jha
2018-02-12 11:54 ` [PATCH 1/4] staging: iio: accel: adis16201: Use SPDX identifier Himanshu Jha
2018-02-12 11:54   ` Himanshu Jha
2018-02-12 11:54 ` [PATCH 2/4] staging: iio: accel: Remove unnecessary comments and add suitable suffix Himanshu Jha
2018-02-12 11:54   ` Himanshu Jha
2018-02-12 12:53   ` Dan Carpenter
2018-02-12 12:53     ` Dan Carpenter
2018-02-12 14:35     ` Himanshu Jha
2018-02-12 14:35       ` Himanshu Jha
2018-02-12 14:57       ` Dan Carpenter
2018-02-12 14:57         ` Dan Carpenter
2018-02-12 19:46         ` Himanshu Jha
2018-02-12 19:46           ` Himanshu Jha
2018-02-17 12:19           ` Jonathan Cameron
2018-02-17 12:19             ` Jonathan Cameron
2018-02-17 12:16         ` Jonathan Cameron
2018-02-17 12:16           ` Jonathan Cameron
2018-02-12 11:54 ` [PATCH 3/4] staging: iio: accel: Use sign_extend32 and adjust a switch statement Himanshu Jha
2018-02-12 11:54   ` Himanshu Jha
2018-02-12 13:10   ` Dan Carpenter
2018-02-12 13:10     ` Dan Carpenter
2018-02-17 12:23     ` Jonathan Cameron
2018-02-17 12:23       ` Jonathan Cameron
2018-02-17 17:24       ` Dan Carpenter [this message]
2018-02-17 17:24         ` Dan Carpenter
2018-02-12 11:54 ` [PATCH 4/4] staging: iio: accel: Move adis16201 driver out of staging Himanshu Jha
2018-02-12 11:54   ` Himanshu Jha
2018-02-12 13:18   ` Dan Carpenter
2018-02-12 13:18     ` Dan Carpenter
2018-02-12 14:41     ` Himanshu Jha
2018-02-12 14:41       ` Himanshu Jha
2018-02-12 14:45       ` Dan Carpenter
2018-02-12 14:45         ` Dan Carpenter
2018-02-17 12:26         ` Jonathan Cameron
2018-02-17 12:26           ` Jonathan Cameron
2018-02-12 14:10   ` Philippe Ombredanne
2018-02-12 14:10     ` Philippe Ombredanne
2018-02-12 14:37     ` Himanshu Jha
2018-02-12 14:37       ` Himanshu Jha
2018-02-12 22:18       ` Philippe Ombredanne

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=20180217172441.2nl632jc3u6himnd@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=21cnbao@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=himanshujha199640@gmail.com \
    --cc=jic23@kernel.org \
    --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 \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.