]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
iio: accel: bma180: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
authorJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 1 May 2021 17:01:03 +0000 (18:01 +0100)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 13 Aug 2021 07:31:09 +0000 (09:31 +0200)
BugLink: https://bugs.launchpad.net/bugs/1938340
[ Upstream commit fc36da3131a747a9367a05caf06de19be1bcc972 ]

To make code more readable, use a structure to express the channel
layout and ensure the timestamp is 8 byte aligned.

Found during an audit of all calls of this function.

Fixes: b9a6a237ffc9 ("iio:bma180: Drop _update_scan_mode()")
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Peter Meerwald <pmeerw@pmeerw.net>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210501170121.512209-2-jic23@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/iio/accel/bma180.c

index 2a6d73cc7333a9ac619ce2e4a3bb1ad6ed8f4c58..9b0018874eec6581feaeedd71e54b5a12a3b41af 100644 (file)
@@ -164,7 +164,11 @@ struct bma180_data {
        int scale;
        int bw;
        bool pmode;
-       u8 buff[16]; /* 3x 16-bit + 8-bit + padding + timestamp */
+       /* Ensure timestamp is naturally aligned */
+       struct {
+               s16 chan[4];
+               s64 timestamp __aligned(8);
+       } scan;
 };
 
 enum bma180_chan {
@@ -943,12 +947,12 @@ static irqreturn_t bma180_trigger_handler(int irq, void *p)
                        mutex_unlock(&data->mutex);
                        goto err;
                }
-               ((s16 *)data->buff)[i++] = ret;
+               data->scan.chan[i++] = ret;
        }
 
        mutex_unlock(&data->mutex);
 
-       iio_push_to_buffers_with_timestamp(indio_dev, data->buff, time_ns);
+       iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, time_ns);
 err:
        iio_trigger_notify_done(indio_dev->trig);