From: Jonathan Cameron <jic23@kernel.org>
To: Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
Cc: linux-iio@vger.kernel.org, lorenzo.bianconi@st.com,
denis.ciocca@st.com, Gregor Boirie <gregor.boirie@parrot.com>
Subject: Re: [PATCH] iio: common: st_sensors: fix channel data parsing
Date: Sat, 1 Oct 2016 14:30:00 +0100 [thread overview]
Message-ID: <45809aef-5396-90fa-1312-677eaeec36da@kernel.org> (raw)
In-Reply-To: <1475093161-7239-1-git-send-email-lorenzo.bianconi@st.com>
On 28/09/16 21:06, Lorenzo Bianconi wrote:
> Using realbits as i2c/spi read len, when that value is not byte aligned
> (e.g 12 bits), lead to skip msb part of out data registers.
> Fix this using storagebits as read length
>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
Hi Lorenzo,
This would ideally have had a fixes tag.
I think it was
Fixes: e7385de5 ("iio:st_sensors: align on storagebits boundaries")
Doing that would also have lead to you to the logic that lead to
this buggy change in the first place. Would also have shown
you that there is another place that probably suffers from the
same sort of issue.
Gregor can you take a look at this please.
If I recall the issue that lead to the original patch it was
that we were miss handling 24 bit values on pressure sensors and
this was intended to pad them?
I think the 'right' fix will be something along the lines of:
unsigned int bytes_to_read = (channel->scan_type.realbits + 7) >> 3;
Should give 2 bytes for a 12 bit and still the 3 bytes needed for a
24 bit read.
Thanks,
Jonathan
> ---
> drivers/iio/common/st_sensors/st_sensors_buffer.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c
> index fe7775b..d01aa34 100644
> --- a/drivers/iio/common/st_sensors/st_sensors_buffer.c
> +++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c
> @@ -30,16 +30,15 @@ static int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf)
>
> for_each_set_bit(i, indio_dev->active_scan_mask, num_data_channels) {q
> const struct iio_chan_spec *channel = &indio_dev->channels[i];
> - unsigned int bytes_to_read = channel->scan_type.realbits >> 3;
> unsigned int storage_bytes =
> channel->scan_type.storagebits >> 3;
>
> buf = PTR_ALIGN(buf, storage_bytes);
> if (sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev,
> channel->address,
> - bytes_to_read, buf,
> + storage_bytes, buf,
> sdata->multiread_bit) <
> - bytes_to_read)
> + storage_bytes)
> return -EIO;
>
> /* Advance the buffer pointer */
>
next prev parent reply other threads:[~2016-10-01 13:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-28 20:06 [PATCH] iio: common: st_sensors: fix channel data parsing Lorenzo Bianconi
2016-10-01 13:30 ` Jonathan Cameron [this message]
2016-10-01 14:18 ` Lorenzo Bianconi
2016-10-01 14:58 ` Jonathan Cameron
2016-10-01 17:32 ` Lorenzo Bianconi
2016-10-03 9:52 ` Gregor Boirie
2016-10-03 10:16 ` Lorenzo Bianconi
2016-10-03 19:35 ` Lorenzo Bianconi
2016-10-03 19:49 ` Jonathan Cameron
2016-10-24 12:51 ` Lorenzo Bianconi
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=45809aef-5396-90fa-1312-677eaeec36da@kernel.org \
--to=jic23@kernel.org \
--cc=denis.ciocca@st.com \
--cc=gregor.boirie@parrot.com \
--cc=linux-iio@vger.kernel.org \
--cc=lorenzo.bianconi83@gmail.com \
--cc=lorenzo.bianconi@st.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.