Commit 43372868 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Luis Henriques

UBUNTU:SAUCE: iio: common: st_sensors: fix channel data parsing

BugLink: http://bugs.launchpad.net/bugs/1650189

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: e7385de5 ("iio:st_sensors: align on storagebits boundaries")
Signed-off-by: default avatarLorenzo Bianconi <lorenzo.bianconi@st.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
(backported from commit fd60b8949f4e85be2b9f364ab9c898c408664518)
(source: git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git)
Signed-off-by: default avatarShrirang Bagul <shrirang.bagul@canonical.com>
Acked-by: default avatarTim Gardner <tim.gardner@canonical.com>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 0bf5510f
......@@ -29,7 +29,8 @@ int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf)
struct st_sensor_data *sdata = iio_priv(indio_dev);
unsigned int num_data_channels = sdata->num_data_channels;
unsigned int byte_for_channel =
indio_dev->channels[0].scan_type.storagebits >> 3;
DIV_ROUND_UP(indio_dev->channels[0].scan_type.realbits +
indio_dev->channels[0].scan_type.shift, 8);
addr = kmalloc(num_data_channels, GFP_KERNEL);
if (!addr) {
......
......@@ -485,8 +485,10 @@ static int st_sensors_read_axis_data(struct iio_dev *indio_dev,
int err;
u8 *outdata;
struct st_sensor_data *sdata = iio_priv(indio_dev);
unsigned int byte_for_channel = ch->scan_type.storagebits >> 3;
unsigned int byte_for_channel;
byte_for_channel = DIV_ROUND_UP(ch->scan_type.realbits +
ch->scan_type.shift, 8);
outdata = kmalloc(byte_for_channel, GFP_KERNEL);
if (!outdata)
return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment