From: Jonathan Cameron <jic23@kernel.org>
To: Shreeya Patel <shreeya.patel23498@gmail.com>
Cc: lars@metafoo.de, Michael.Hennerich@analog.com, knaack.h@gmx.de,
pmeerw@pmeerw.net, linux-iio@vger.kernel.org,
devel@driverdev.osuosl.org, daniel.baluta@nxp.com
Subject: Re: [PATCH 3/3] Staging: iio: adis16209: Use sign_extend32 and adjust a switch statement
Date: Sun, 18 Feb 2018 12:47:15 +0000 [thread overview]
Message-ID: <20180218124715.62a86f22@archlinux> (raw)
In-Reply-To: <317f97b7a3b53bf3ae1457d7c38f78befc4b99db.1518883035.git.shreeya.patel23498@gmail.com>
On Sat, 17 Feb 2018 21:51:35 +0530
Shreeya Patel <shreeya.patel23498@gmail.com> 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.
Two items, two patches please.
The -EINVAL is a bit of an odd one. We know it can never happen and
in reality we only add it to suppress the static checker warnings
that may otherwise ensue. I would definitely not say that it helps
readability. The change to the switch statement makes it clear there
are only two channels so is semantically clearer to my mind and it is
that which I argued improved readability.
Jonathan
>
> Signed-off-by: Shreeya Patel <shreeya.patel23498@gmail.com>
> ---
> drivers/staging/iio/accel/adis16209.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/staging/iio/accel/adis16209.c b/drivers/staging/iio/accel/adis16209.c
> index 6101212..f7c228b 100644
> --- a/drivers/staging/iio/accel/adis16209.c
> +++ b/drivers/staging/iio/accel/adis16209.c
> @@ -150,10 +150,16 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
> switch (chan->type) {
> case IIO_VOLTAGE:
> *val = 0;
> - if (chan->channel == 0)
> + switch (chan->channel) {
> + case 0:
> *val2 = 305180;
> - else
> + break;
> + case 1:
> *val2 = 610500;
> + break;
> + default:
> + return -EINVAL;
> + }
> return IIO_VAL_INT_PLUS_MICRO;
> case IIO_TEMP:
> *val = -470;
> @@ -187,9 +193,8 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
> ret = adis_read_reg_16(st, addr, &val16);
> if (ret)
> return ret;
> - val16 &= (1 << bits) - 1;
> - val16 = (s16)(val16 << (16 - bits)) >> (16 - bits);
> - *val = val16;
> +
> + *val = sign_extend32(val16, bits - 1);
> return IIO_VAL_INT;
> }
> return -EINVAL;
prev parent reply other threads:[~2018-02-18 12:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-17 16:02 [PATCH 0/3] adis16209 driver cleanup Shreeya Patel
2018-02-17 16:04 ` [PATCH 1/3] Staging: iio: adis16209: Use SPDX identifier Shreeya Patel
2018-02-18 11:31 ` Himanshu Jha
2018-02-18 11:37 ` Shreeya Patel
2018-02-18 12:02 ` Jonathan Cameron
2018-02-18 12:08 ` Lars-Peter Clausen
2018-02-18 12:14 ` Lars-Peter Clausen
2018-02-18 12:51 ` Jonathan Cameron
2018-02-18 12:04 ` Jonathan Cameron
2018-02-17 16:07 ` [PATCH 2/3] Staging: iio: adis16209: Remove unnecessary comments and add suitable suffix Shreeya Patel
2018-02-18 12:44 ` Jonathan Cameron
2018-02-17 16:21 ` [PATCH 3/3] Staging: iio: adis16209: Use sign_extend32 and adjust a switch statement Shreeya Patel
2018-02-18 12:47 ` 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=20180218124715.62a86f22@archlinux \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=daniel.baluta@nxp.com \
--cc=devel@driverdev.osuosl.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
--cc=shreeya.patel23498@gmail.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;
as well as URLs for NNTP newsgroup(s).