Skip to content

Commit

Permalink
iio: humidity: am2315: Fix buffer alignment in iio_push_to_buffers_wi…
Browse files Browse the repository at this point in the history
…th_timestamp()

[ Upstream commit f4ca2e2 ]

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 uses of
iio_push_to_buffers_with_timestamp()

Fixes: 0d96d5e ("iio: humidity: Add triggered buffer support for AM2315")
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210501170121.512209-12-jic23@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
jic23 authored and gregkh committed Jul 14, 2021
1 parent 8ea8782 commit c61ac1f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions drivers/iio/humidity/am2315.c
Expand Up @@ -33,7 +33,11 @@
struct am2315_data {
struct i2c_client *client;
struct mutex lock;
s16 buffer[8]; /* 2x16-bit channels + 2x16 padding + 4x16 timestamp */
/* Ensure timestamp is naturally aligned */
struct {
s16 chans[2];
s64 timestamp __aligned(8);
} scan;
};

struct am2315_sensor_data {
Expand Down Expand Up @@ -167,20 +171,20 @@ static irqreturn_t am2315_trigger_handler(int irq, void *p)

mutex_lock(&data->lock);
if (*(indio_dev->active_scan_mask) == AM2315_ALL_CHANNEL_MASK) {
data->buffer[0] = sensor_data.hum_data;
data->buffer[1] = sensor_data.temp_data;
data->scan.chans[0] = sensor_data.hum_data;
data->scan.chans[1] = sensor_data.temp_data;
} else {
i = 0;
for_each_set_bit(bit, indio_dev->active_scan_mask,
indio_dev->masklength) {
data->buffer[i] = (bit ? sensor_data.temp_data :
sensor_data.hum_data);
data->scan.chans[i] = (bit ? sensor_data.temp_data :
sensor_data.hum_data);
i++;
}
}
mutex_unlock(&data->lock);

iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
iio_push_to_buffers_with_timestamp(indio_dev, &data->scan,
pf->timestamp);
err:
iio_trigger_notify_done(indio_dev->trig);
Expand Down

0 comments on commit c61ac1f

Please sign in to comment.