diff options
author | Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> | 2016-11-16 16:15:28 -0500 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2016-12-31 09:32:09 -0500 |
commit | 65c8aea07de11b6507efa175edb44bd8b4488218 (patch) | |
tree | f16e596bed7448b837e52ddd5da385636de27003 /drivers | |
parent | b4e8a0eb718749455601fa7b283febc42cca8957 (diff) |
iio: common: st_sensors: fix channel data parsing
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 taking into account scan_type.shift in addition to
scan_type.realbits as read length:
read_len = DIV_ROUND_UP(realbits + shift, 8)
This fix has been tested on 8, 12, 16, 24 bit sensors
Fixes: e7385de5291e ("iio:st_sensors: align on storagebits boundaries")
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/iio/common/st_sensors/st_sensors_buffer.c | 4 | ||||
-rw-r--r-- | drivers/iio/common/st_sensors/st_sensors_core.c | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c index fe7775bb3740..df4045203a07 100644 --- a/drivers/iio/common/st_sensors/st_sensors_buffer.c +++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c | |||
@@ -30,7 +30,9 @@ static int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) | |||
30 | 30 | ||
31 | for_each_set_bit(i, indio_dev->active_scan_mask, num_data_channels) { | 31 | for_each_set_bit(i, indio_dev->active_scan_mask, num_data_channels) { |
32 | const struct iio_chan_spec *channel = &indio_dev->channels[i]; | 32 | const struct iio_chan_spec *channel = &indio_dev->channels[i]; |
33 | unsigned int bytes_to_read = channel->scan_type.realbits >> 3; | 33 | unsigned int bytes_to_read = |
34 | DIV_ROUND_UP(channel->scan_type.realbits + | ||
35 | channel->scan_type.shift, 8); | ||
34 | unsigned int storage_bytes = | 36 | unsigned int storage_bytes = |
35 | channel->scan_type.storagebits >> 3; | 37 | channel->scan_type.storagebits >> 3; |
36 | 38 | ||
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c index 975a1f19f747..d5cf7f31eaf9 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.c +++ b/drivers/iio/common/st_sensors/st_sensors_core.c | |||
@@ -483,8 +483,10 @@ static int st_sensors_read_axis_data(struct iio_dev *indio_dev, | |||
483 | int err; | 483 | int err; |
484 | u8 *outdata; | 484 | u8 *outdata; |
485 | struct st_sensor_data *sdata = iio_priv(indio_dev); | 485 | struct st_sensor_data *sdata = iio_priv(indio_dev); |
486 | unsigned int byte_for_channel = ch->scan_type.realbits >> 3; | 486 | unsigned int byte_for_channel; |
487 | 487 | ||
488 | byte_for_channel = DIV_ROUND_UP(ch->scan_type.realbits + | ||
489 | ch->scan_type.shift, 8); | ||
488 | outdata = kmalloc(byte_for_channel, GFP_KERNEL); | 490 | outdata = kmalloc(byte_for_channel, GFP_KERNEL); |
489 | if (!outdata) | 491 | if (!outdata) |
490 | return -ENOMEM; | 492 | return -ENOMEM; |