]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
iio:st_sensors: align on storagebits boundaries
authorGregor Boirie <gregor.boirie@parrot.com>
Mon, 27 Jun 2016 10:38:52 +0000 (12:38 +0200)
committerThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Thu, 6 Apr 2017 08:23:50 +0000 (09:23 +0100)
BugLink: https://bugs.launchpad.net/bugs/1676356
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>
(cherry picked from commit e7385de5291e347f5bc85985acdce3a3f5096667)
Signed-off-by: Shrirang Bagul <shrirang.bagul@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Tim Gardner <tim.gardner@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
drivers/iio/common/st_sensors/st_sensors_buffer.c
drivers/iio/common/st_sensors/st_sensors_core.c

index f2e876d57c30c60314d984f9779661b97b8a5e9e..c803a4a854636d70c360a65eb9644a67254512a8 100644 (file)
 
 int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf)
 {
-       int i, len;
-       int total = 0;
+       int i;
        struct st_sensor_data *sdata = iio_priv(indio_dev);
        unsigned int num_data_channels = sdata->num_data_channels;
        unsigned int byte_for_channel =
                DIV_ROUND_UP(indio_dev->channels[0].scan_type.realbits +
                                indio_dev->channels[0].scan_type.shift, 8);
 
-       for (i = 0; i < num_data_channels; i++) {
-               unsigned int bytes_to_read;
-
-               if (test_bit(i, indio_dev->active_scan_mask)) {
-                       bytes_to_read = indio_dev->channels[i].scan_type.storagebits >> 3;
-                       len = sdata->tf->read_multiple_byte(&sdata->tb,
-                               sdata->dev, indio_dev->channels[i].address,
-                               bytes_to_read,
-                               buf + total, sdata->multiread_bit);
-
-                       if (len < bytes_to_read)
-                               return -EIO;
-
-                       /* Advance the buffer pointer */
-                       total += len;
-               }
+       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,
+                                                 sdata->multiread_bit) <
+                   bytes_to_read)
+                       return -EIO;
+
+               /* Advance the buffer pointer */
+               buf += storage_bytes;
        }
 
-       return total;
+       return 0;
 }
 EXPORT_SYMBOL(st_sensors_get_buffer_element);
 
index 8f0e8ceb98518d67b4d289e63d43290a1ae49dec..066cfdbb723e6f371d3ed86a368b3bf9221abd3e 100644 (file)
@@ -485,7 +485,7 @@ 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;
+       unsigned int byte_for_channel = ch->scan_type.realbits >> 3;
 
        byte_for_channel = DIV_ROUND_UP(ch->scan_type.realbits +
                                        ch->scan_type.shift, 8);