[PATCH v3 1/3] iio: accel: bmc150: use aligned scan buffer for both trigger and fifo
From: Yash Suthar
Date: Tue Aug 25 2026 - 04:52:42 EST
Drop buffer as duplicate and s16 is not correct we needed __le16 as little
endian, keep scan at the end of the bmc150_accel_data struct with
IIO_DMA_MINALIGN, and use it for both paths.
In trigger handle, replaced AXIS_MAX with sizeof(data->scan.channels).
Additionally, ensure mutex is held across both read and push to get
DMA safety for the scan buffer.
Fixes: bd7fe5b71918 ("iio: accel: BMC150 accel support")
Suggested-by: Jonathan Cameron <jic23@xxxxxxxxxx>
Signed-off-by: Yash Suthar <yashsuthar983@xxxxxxxxx>
---
drivers/iio/accel/bmc150-accel-core.c | 8 ++++----
drivers/iio/accel/bmc150-accel.h | 14 +++++---------
2 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
index dc8a6285cf3d..1472e0d1ef65 100644
--- a/drivers/iio/accel/bmc150-accel-core.c
+++ b/drivers/iio/accel/bmc150-accel-core.c
@@ -131,7 +131,6 @@ enum bmc150_accel_axis {
AXIS_X,
AXIS_Y,
AXIS_Z,
- AXIS_MAX,
};
enum bmc150_power_modes {
@@ -1191,14 +1190,15 @@ static irqreturn_t bmc150_accel_trigger_handler(int irq, void *p)
mutex_lock(&data->mutex);
ret = regmap_bulk_read(data->regmap, BMC150_ACCEL_REG_XOUT_L,
- data->buffer, AXIS_MAX * 2);
- mutex_unlock(&data->mutex);
+ data->scan.channels,
+ sizeof(data->scan.channels));
if (ret < 0)
goto err_read;
- iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
+ iio_push_to_buffers_with_timestamp(indio_dev, &data->scan,
pf->timestamp);
err_read:
+ mutex_unlock(&data->mutex);
iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED;
diff --git a/drivers/iio/accel/bmc150-accel.h b/drivers/iio/accel/bmc150-accel.h
index e8f26198359f..9deff256aed5 100644
--- a/drivers/iio/accel/bmc150-accel.h
+++ b/drivers/iio/accel/bmc150-accel.h
@@ -64,15 +64,6 @@ struct bmc150_accel_data {
struct bmc150_accel_trigger triggers[BMC150_ACCEL_TRIGGERS];
struct mutex mutex;
u8 fifo_mode, watermark;
- s16 buffer[8];
- /*
- * Ensure there is sufficient space and correct alignment for
- * the timestamp if enabled
- */
- struct {
- __le16 channels[3];
- aligned_s64 ts;
- } scan;
u8 bw_bits;
u32 slope_dur;
u32 slope_thres;
@@ -85,6 +76,11 @@ struct bmc150_accel_data {
void (*resume_callback)(struct device *dev);
struct delayed_work resume_work;
struct iio_mount_matrix orientation;
+ /* Ensure correct alignment of timestamp and DMA safety */
+ struct {
+ __le16 channels[3];
+ aligned_s64 ts;
+ } scan __aligned(IIO_DMA_MINALIGN);
};
int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
--
2.43.0