From: Jonathan Cameron <jic23@kernel.org>
To: Sandhya Bankar <bankarsandhya512@gmail.com>,
knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
linux-iio@vger.kernel.org
Cc: outreachy-kernel@googlegroups.com
Subject: Re: [PATCH] drivers: iio: magnetometer: Fix sparse endianness warnings cast to restricted __le16
Date: Sun, 25 Sep 2016 09:53:54 +0100 [thread overview]
Message-ID: <8cef9ca5-c5e7-1bda-beb1-f59786469a62@kernel.org> (raw)
In-Reply-To: <20160924212253.GA25982@localhost.localdomain>
On 24/09/16 22:22, Sandhya Bankar wrote:
> Fix the following sparse endianness warnings:
>
> drivers/iio/magnetometer/ak8975.c:716:16: warning: cast to restricted __le16
> drivers/iio/magnetometer/ak8975.c:837:19: warning: cast to restricted __le16
> drivers/iio/magnetometer/ak8975.c:838:19: warning: cast to restricted __le16
> drivers/iio/magnetometer/ak8975.c:839:19: warning: cast to restricted __le16
>
>
> Signed-off-by: Sandhya Bankar <bankarsandhya512@gmail.com>
Comment inline. This one is slightly more complex than it first looks.
Jonathan
>
> ---
> drivers/iio/magnetometer/ak8975.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
> index af8606c..66a85a8 100644
> --- a/drivers/iio/magnetometer/ak8975.c
> +++ b/drivers/iio/magnetometer/ak8975.c
> @@ -690,6 +690,7 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
> struct ak8975_data *data = iio_priv(indio_dev);
> const struct i2c_client *client = data->client;
> const struct ak_def *def = data->def;
> + __le16 rval;
> u16 buff;
> int ret;
>
> @@ -703,7 +704,7 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
>
> ret = i2c_smbus_read_i2c_block_data_or_emulated(
> client, def->data_regs[index],
> - sizeof(buff), (u8*)&buff);
> + sizeof(rval), (u8*)&rval);
> if (ret < 0)
> goto exit;
>
> @@ -713,7 +714,7 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
> pm_runtime_put_autosuspend(&data->client->dev);
>
> /* Swap bytes and convert to valid range. */
> - buff = le16_to_cpu(buff);
> + buff = le16_to_cpu(rval);
> *val = clamp_t(s16, buff, -def->range, def->range);
> return IIO_VAL_INT;
>
> @@ -813,6 +814,7 @@ static void ak8975_fill_buffer(struct iio_dev *indio_dev)
> const struct ak_def *def = data->def;
> int ret;
> s16 buff[8]; /* 3 x 16 bits axis values + 1 aligned 64 bits timestamp */
> + __le16 fval[8];
This one is more interesting. Check how many values of fval are actually
used. Buff needs some padding to take a timestamp inserted (rather
surprisingly by the iio_push_to_buffers_with_timestamp call), lval doesn't.
>
> mutex_lock(&data->lock);
>
> @@ -826,17 +828,17 @@ static void ak8975_fill_buffer(struct iio_dev *indio_dev)
> */
> ret = i2c_smbus_read_i2c_block_data_or_emulated(client,
> def->data_regs[0],
> - 3 * sizeof(buff[0]),
> - (u8 *)buff);
> + 3 * sizeof(fval[0]),
> + (u8 *)fval);
> if (ret < 0)
> goto unlock;
>
> mutex_unlock(&data->lock);
>
> /* Clamp to valid range. */
> - buff[0] = clamp_t(s16, le16_to_cpu(buff[0]), -def->range, def->range);
> - buff[1] = clamp_t(s16, le16_to_cpu(buff[1]), -def->range, def->range);
> - buff[2] = clamp_t(s16, le16_to_cpu(buff[2]), -def->range, def->range);
> + buff[0] = clamp_t(s16, le16_to_cpu(fval[0]), -def->range, def->range);
> + buff[1] = clamp_t(s16, le16_to_cpu(fval[1]), -def->range, def->range);
> + buff[2] = clamp_t(s16, le16_to_cpu(fval[2]), -def->range, def->range);
>
> iio_push_to_buffers_with_timestamp(indio_dev, buff,
> iio_get_time_ns(indio_dev));
>
prev parent reply other threads:[~2016-09-25 8:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-24 21:22 [PATCH] drivers: iio: magnetometer: Fix sparse endianness warnings cast to restricted __le16 Sandhya Bankar
2016-09-25 8:53 ` 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=8cef9ca5-c5e7-1bda-beb1-f59786469a62@kernel.org \
--to=jic23@kernel.org \
--cc=bankarsandhya512@gmail.com \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=outreachy-kernel@googlegroups.com \
--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 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).