iio:st_sensors: align on storagebits boundaries

Ensure triggered buffering memory accesses are properly aligned on per
channel storagebits boundaries.

Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
Gregor Boirie 2016-06-27 12:38:52 +02:00 committed by Jonathan Cameron
parent fc6bd7275b
commit e7385de529
2 changed files with 17 additions and 18 deletions

View file

@ -24,30 +24,29 @@
static int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) static 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;
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;
unsigned int storage_bytes =
channel->scan_type.storagebits >> 3;
if (test_bit(i, indio_dev->active_scan_mask)) { buf = PTR_ALIGN(buf, storage_bytes);
bytes_to_read = indio_dev->channels[i].scan_type.storagebits >> 3; if (sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev,
len = sdata->tf->read_multiple_byte(&sdata->tb, channel->address,
sdata->dev, indio_dev->channels[i].address, bytes_to_read, buf,
bytes_to_read, sdata->multiread_bit) <
buf + total, sdata->multiread_bit); bytes_to_read)
return -EIO;
if (len < bytes_to_read) /* Advance the buffer pointer */
return -EIO; buf += storage_bytes;
/* Advance the buffer pointer */
total += len;
}
} }
return total; return 0;
} }
irqreturn_t st_sensors_trigger_handler(int irq, void *p) irqreturn_t st_sensors_trigger_handler(int irq, void *p)

View file

@ -490,7 +490,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 = ch->scan_type.storagebits >> 3; unsigned int byte_for_channel = ch->scan_type.realbits >> 3;
outdata = kmalloc(byte_for_channel, GFP_KERNEL); outdata = kmalloc(byte_for_channel, GFP_KERNEL);
if (!outdata) if (!outdata)