[PATCH] iio: proximity: sx_common: use stack allocated buffer for scan data
From: David Lechner
Date: Fri Jul 11 2025 - 11:55:27 EST
Use IIO_DECLARE_BUFFER_WITH_TS() to declare a stack allocated buffer
in sx_common_trigger_handler(). Since the scan buffer isn't used outside
of this function and doesn't need to be DMA-safe, it doesn't need to be
in struct sx_common_data.
Signed-off-by: David Lechner <dlechner@xxxxxxxxxxxx>
---
drivers/iio/proximity/sx_common.c | 7 ++++---
drivers/iio/proximity/sx_common.h | 6 ------
2 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/proximity/sx_common.c b/drivers/iio/proximity/sx_common.c
index 59b35e40739b0d931dbac076ca5c83ba421ba766..fae035e8d2f5a40ed7379dd6e306f84878a9bef0 100644
--- a/drivers/iio/proximity/sx_common.c
+++ b/drivers/iio/proximity/sx_common.c
@@ -361,6 +361,7 @@ static irqreturn_t sx_common_irq_thread_handler(int irq, void *private)
static irqreturn_t sx_common_trigger_handler(int irq, void *private)
{
+ IIO_DECLARE_BUFFER_WITH_TS(__be16, buffer, SX_COMMON_MAX_NUM_CHANNELS);
struct iio_poll_func *pf = private;
struct iio_dev *indio_dev = pf->indio_dev;
struct sx_common_data *data = iio_priv(indio_dev);
@@ -376,11 +377,11 @@ static irqreturn_t sx_common_trigger_handler(int irq, void *private)
if (ret)
goto out;
- data->buffer.channels[i++] = val;
+ buffer[i++] = val;
}
- iio_push_to_buffers_with_ts(indio_dev, &data->buffer,
- sizeof(data->buffer), pf->timestamp);
+ iio_push_to_buffers_with_ts(indio_dev, buffer, sizeof(buffer),
+ pf->timestamp);
out:
mutex_unlock(&data->mutex);
diff --git a/drivers/iio/proximity/sx_common.h b/drivers/iio/proximity/sx_common.h
index 259b5c695233b4e295ad8ae2b05fceeaa4a7ae61..97b264aa50b0c9811ce6b42be34eace03eae2627 100644
--- a/drivers/iio/proximity/sx_common.h
+++ b/drivers/iio/proximity/sx_common.h
@@ -122,12 +122,6 @@ struct sx_common_data {
unsigned long chan_prox_stat;
bool trigger_enabled;
- /* Ensure correct alignment of timestamp when present. */
- struct {
- __be16 channels[SX_COMMON_MAX_NUM_CHANNELS];
- aligned_s64 ts;
- } buffer;
-
unsigned int suspend_ctrl;
unsigned long chan_read;
unsigned long chan_event;
---
base-commit: f8f559752d573a051a984adda8d2d1464f92f954
change-id: 20250711-iio-use-more-iio_declare_buffer_with_ts-5-f4c91d73037d
Best regards,
--
David Lechner <dlechner@xxxxxxxxxxxx>