linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: common: st_sensors: fix channel data parsing
@ 2016-09-28 20:06 Lorenzo Bianconi
  2016-10-01 13:30 ` Jonathan Cameron
  0 siblings, 1 reply; 10+ messages in thread
From: Lorenzo Bianconi @ 2016-09-28 20:06 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, lorenzo.bianconi, denis.ciocca

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>
---
 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) {
 		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 */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-10-24 12:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-28 20:06 [PATCH] iio: common: st_sensors: fix channel data parsing Lorenzo Bianconi
2016-10-01 13:30 ` Jonathan Cameron
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

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).