[PATCH] iio: accel: bma180: use stack allocated buffer for scan

David Lechner posted 1 patch 2 months, 4 weeks ago
There is a newer version of this series
drivers/iio/accel/bma180.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
[PATCH] iio: accel: bma180: use stack allocated buffer for scan
Posted by David Lechner 2 months, 4 weeks ago
Use IIO_DECLARE_BUFFER_WITH_TS() to declare a stack allocated buffer
in bma180_trigger_handler(). Since the scan buffer isn't used outside
of this function, it doesn't need to be in struct bma180_data.

Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/accel/bma180.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
index 4fccbcb76e0423bee37463a72c637af80e356a19..d83d5becca6fc72b855310a31c3de5443e4e2311 100644
--- a/drivers/iio/accel/bma180.c
+++ b/drivers/iio/accel/bma180.c
@@ -139,11 +139,6 @@ struct bma180_data {
 	int scale;
 	int bw;
 	bool pmode;
-	/* Ensure timestamp is naturally aligned */
-	struct {
-		s16 chan[4];
-		aligned_s64 timestamp;
-	} scan;
 };
 
 enum bma180_chan {
@@ -865,6 +860,7 @@ static const struct bma180_part_info bma180_part_info[] = {
 
 static irqreturn_t bma180_trigger_handler(int irq, void *p)
 {
+	IIO_DECLARE_BUFFER_WITH_TS(s16, scan, 4);
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct bma180_data *data = iio_priv(indio_dev);
@@ -879,12 +875,12 @@ static irqreturn_t bma180_trigger_handler(int irq, void *p)
 			mutex_unlock(&data->mutex);
 			goto err;
 		}
-		data->scan.chan[i++] = ret;
+		scan[i++] = ret;
 	}
 
 	mutex_unlock(&data->mutex);
 
-	iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan), time_ns);
+	iio_push_to_buffers_with_ts(indio_dev, scan, sizeof(scan), time_ns);
 err:
 	iio_trigger_notify_done(indio_dev->trig);
 

---
base-commit: f8f559752d573a051a984adda8d2d1464f92f954
change-id: 20250710-iio-use-more-iio_declare_buffer_with_ts-0924382d38c6

Best regards,
-- 
David Lechner <dlechner@baylibre.com>
Re: [PATCH] iio: accel: bma180: use stack allocated buffer for scan
Posted by Jonathan Cameron 2 months, 3 weeks ago
On Thu, 10 Jul 2025 18:00:05 -0500
David Lechner <dlechner@baylibre.com> wrote:

> Use IIO_DECLARE_BUFFER_WITH_TS() to declare a stack allocated buffer
> in bma180_trigger_handler(). Since the scan buffer isn't used outside
> of this function, it doesn't need to be in struct bma180_data.
> 
> Signed-off-by: David Lechner <dlechner@baylibre.com>
As with the other similar cases I'm a fan of structures whenever
we can because the let people see the memory layout in the code.

Jonathan

> ---
>  drivers/iio/accel/bma180.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
> index 4fccbcb76e0423bee37463a72c637af80e356a19..d83d5becca6fc72b855310a31c3de5443e4e2311 100644
> --- a/drivers/iio/accel/bma180.c
> +++ b/drivers/iio/accel/bma180.c
> @@ -139,11 +139,6 @@ struct bma180_data {
>  	int scale;
>  	int bw;
>  	bool pmode;
> -	/* Ensure timestamp is naturally aligned */
> -	struct {
> -		s16 chan[4];
> -		aligned_s64 timestamp;
> -	} scan;
>  };
>  
>  enum bma180_chan {
> @@ -865,6 +860,7 @@ static const struct bma180_part_info bma180_part_info[] = {
>  
>  static irqreturn_t bma180_trigger_handler(int irq, void *p)
>  {
> +	IIO_DECLARE_BUFFER_WITH_TS(s16, scan, 4);
>  	struct iio_poll_func *pf = p;
>  	struct iio_dev *indio_dev = pf->indio_dev;
>  	struct bma180_data *data = iio_priv(indio_dev);
> @@ -879,12 +875,12 @@ static irqreturn_t bma180_trigger_handler(int irq, void *p)
>  			mutex_unlock(&data->mutex);
>  			goto err;
>  		}
> -		data->scan.chan[i++] = ret;
> +		scan[i++] = ret;
>  	}
>  
>  	mutex_unlock(&data->mutex);
>  
> -	iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan), time_ns);
> +	iio_push_to_buffers_with_ts(indio_dev, scan, sizeof(scan), time_ns);
>  err:
>  	iio_trigger_notify_done(indio_dev->trig);
>  
> 
> ---
> base-commit: f8f559752d573a051a984adda8d2d1464f92f954
> change-id: 20250710-iio-use-more-iio_declare_buffer_with_ts-0924382d38c6
> 
> Best regards,
Re: [PATCH] iio: accel: bma180: use stack allocated buffer for scan
Posted by Andy Shevchenko 2 months, 4 weeks ago
On Thu, Jul 10, 2025 at 06:00:05PM -0500, David Lechner wrote:
> Use IIO_DECLARE_BUFFER_WITH_TS() to declare a stack allocated buffer
> in bma180_trigger_handler(). Since the scan buffer isn't used outside
> of this function, it doesn't need to be in struct bma180_data.

LGTM as we don't use scan buffer directly in IO, we just assign a value
from somewhere else which is already on stack.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
With Best Regards,
Andy Shevchenko