From: arnd@arndb.de
To: Somya Anand <somyaanand214@gmail.com>,
outreachy-kernel <outreachy-kernel@googlegroups.com>
Subject: Re: [Outreachy kernel] [PATCH] Staging: iio: Change data type in adis16220_read_16bit to u16
Date: Fri, 6 Mar 2015 10:12:47 +0100 (CET) [thread overview]
Message-ID: <899581237.61503.1425633167521.JavaMail.open-xchange@oxbaltgw05.schlund.de> (raw)
In-Reply-To: <1425630960-7142-1-git-send-email-somyaanand214@gmail.com>
> Somya Anand <somyaanand214@gmail.com> hat am 6. März 2015 um 09:36
> geschrieben:
> diff --git a/drivers/staging/iio/accel/adis16220_core.c
> b/drivers/staging/iio/accel/adis16220_core.c
> index d478f51..7a4a0fd 100644
> --- a/drivers/staging/iio/accel/adis16220_core.c
> +++ b/drivers/staging/iio/accel/adis16220_core.c
> @@ -28,16 +28,15 @@ static ssize_t adis16220_read_16bit(struct device *dev,
> struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> struct adis16220_state *st = iio_priv(indio_dev);
> ssize_t ret;
> - s16 val = 0;
> + u16 val = 0;
>
> /* Take the iio_dev status lock */
> mutex_lock(&indio_dev->mlock);
In a patch like this, it would be best to also drop the initialization to zero,
which is
not used here. Not initializing it helps the compiler provide useful warnings if
the code gets changed to return an otherwise uninitialized result.
> - ret = adis_read_reg_16(&st->adis, this_attr->address,
> - (u16 *)&val);
> + ret = adis_read_reg_16(&st->adis, this_attr->address, &val);
> mutex_unlock(&indio_dev->mlock);
> if (ret)
> return ret;
> - return sprintf(buf, "%d\n", val);
> + return sprintf(buf, "%u\n", val);
> }
>
This looks wrong: Unless you know better, you should assume that the sprintf
format
string is correct and that the value is indeed signed for the purpose of this
file.
The reason why adis_read_reg_16() takes a u16 argument instead of s16 is that it
accesses a register that doesn't have a concept of signedness. I would just
leave
the code as it is, alternatively you could have two variables and explicitly
cast from
u16 to s16 with a comment.
Arnd
prev parent reply other threads:[~2015-03-06 9:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-06 8:36 [PATCH] Staging: iio: Change data type in adis16220_read_16bit to u16 Somya Anand
2015-03-06 8:58 ` [Outreachy kernel] " Daniel Baluta
2015-03-06 9:15 ` Lars-Peter Clausen
2015-03-06 9:55 ` Somya Anand
2015-03-06 9:12 ` arnd [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=899581237.61503.1425633167521.JavaMail.open-xchange@oxbaltgw05.schlund.de \
--to=arnd@arndb.de \
--cc=outreachy-kernel@googlegroups.com \
--cc=somyaanand214@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 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.