Commit 3ab3aa2e authored by Jonathan Cameron's avatar Jonathan Cameron
Browse files

iio: accel: kxcjk-1013: Fix buffer alignment in iio_push_to_buffers_with_timestamp()



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: 1a4fbf6a ("iio: accel: kxcjk1013 3-axis accelerometer driver")
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210501170121.512209-5-jic23@kernel.org
parent c6559bf7
Loading
Loading
Loading
Loading
+14 −10
Original line number Diff line number Diff line
@@ -233,6 +233,13 @@ static const struct kx_chipset_regs kx0231025_regs = {
	.wake_thres	= KX023_REG_ATH,
};

enum kxcjk1013_axis {
	AXIS_X,
	AXIS_Y,
	AXIS_Z,
	AXIS_MAX
};

struct kxcjk1013_data {
	struct regulator_bulk_data regulators[2];
	struct i2c_client *client;
@@ -240,7 +247,11 @@ struct kxcjk1013_data {
	struct iio_trigger *motion_trig;
	struct iio_mount_matrix orientation;
	struct mutex mutex;
	s16 buffer[8];
	/* Ensure timestamp naturally aligned */
	struct {
		s16 chans[AXIS_MAX];
		s64 timestamp __aligned(8);
	} scan;
	u8 odr_bits;
	u8 range;
	int wake_thres;
@@ -255,13 +266,6 @@ struct kxcjk1013_data {
	const struct kx_chipset_regs *regs;
};

enum kxcjk1013_axis {
	AXIS_X,
	AXIS_Y,
	AXIS_Z,
	AXIS_MAX,
};

enum kxcjk1013_mode {
	STANDBY,
	OPERATION,
@@ -1208,12 +1212,12 @@ static irqreturn_t kxcjk1013_trigger_handler(int irq, void *p)
	ret = i2c_smbus_read_i2c_block_data_or_emulated(data->client,
							KXCJK1013_REG_XOUT_L,
							AXIS_MAX * 2,
							(u8 *)data->buffer);
							(u8 *)data->scan.chans);
	mutex_unlock(&data->mutex);
	if (ret < 0)
		goto err;

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