Commit 1262c110 authored by Gregor Boirie's avatar Gregor Boirie Committed by Thadeu Lima de Souza Cascardo

iio:st_sensors: align on storagebits boundaries

BugLink: https://bugs.launchpad.net/bugs/1676356

Ensure triggered buffering memory accesses are properly aligned on per
channel storagebits boundaries.
Signed-off-by: default avatarGregor Boirie <gregor.boirie@parrot.com>
Tested-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
(cherry picked from commit e7385de5)
Signed-off-by: default avatarShrirang Bagul <shrirang.bagul@canonical.com>
Acked-by: default avatarStefan Bader <stefan.bader@canonical.com>
Acked-by: default avatarTim Gardner <tim.gardner@canonical.com>
Signed-off-by: default avatarThadeu Lima de Souza Cascardo <cascardo@canonical.com>
parent ddf4bec3
...@@ -24,33 +24,32 @@ ...@@ -24,33 +24,32 @@
int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf)
{ {
int i, len; int i;
int total = 0;
struct st_sensor_data *sdata = iio_priv(indio_dev); struct st_sensor_data *sdata = iio_priv(indio_dev);
unsigned int num_data_channels = sdata->num_data_channels; unsigned int num_data_channels = sdata->num_data_channels;
unsigned int byte_for_channel = unsigned int byte_for_channel =
DIV_ROUND_UP(indio_dev->channels[0].scan_type.realbits + DIV_ROUND_UP(indio_dev->channels[0].scan_type.realbits +
indio_dev->channels[0].scan_type.shift, 8); indio_dev->channels[0].scan_type.shift, 8);
for (i = 0; i < num_data_channels; i++) { for_each_set_bit(i, indio_dev->active_scan_mask, num_data_channels) {
unsigned int bytes_to_read; const struct iio_chan_spec *channel = &indio_dev->channels[i];
unsigned int bytes_to_read = channel->scan_type.realbits >> 3;
if (test_bit(i, indio_dev->active_scan_mask)) { unsigned int storage_bytes =
bytes_to_read = indio_dev->channels[i].scan_type.storagebits >> 3; channel->scan_type.storagebits >> 3;
len = sdata->tf->read_multiple_byte(&sdata->tb,
sdata->dev, indio_dev->channels[i].address, buf = PTR_ALIGN(buf, storage_bytes);
bytes_to_read, if (sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev,
buf + total, sdata->multiread_bit); channel->address,
bytes_to_read, buf,
if (len < bytes_to_read) sdata->multiread_bit) <
return -EIO; bytes_to_read)
return -EIO;
/* Advance the buffer pointer */
total += len; /* Advance the buffer pointer */
} buf += storage_bytes;
} }
return total; return 0;
} }
EXPORT_SYMBOL(st_sensors_get_buffer_element); EXPORT_SYMBOL(st_sensors_get_buffer_element);
......
...@@ -485,7 +485,7 @@ static int st_sensors_read_axis_data(struct iio_dev *indio_dev, ...@@ -485,7 +485,7 @@ static int st_sensors_read_axis_data(struct iio_dev *indio_dev,
int err; int err;
u8 *outdata; u8 *outdata;
struct st_sensor_data *sdata = iio_priv(indio_dev); struct st_sensor_data *sdata = iio_priv(indio_dev);
unsigned int byte_for_channel; unsigned int byte_for_channel = ch->scan_type.realbits >> 3;
byte_for_channel = DIV_ROUND_UP(ch->scan_type.realbits + byte_for_channel = DIV_ROUND_UP(ch->scan_type.realbits +
ch->scan_type.shift, 8); ch->scan_type.shift, 8);
......
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