* [PATCH] iio: accel: bma180: use stack allocated buffer for scan
@ 2025-07-10 23:00 David Lechner
2025-07-11 6:29 ` Andy Shevchenko
2025-07-13 14:13 ` Jonathan Cameron
0 siblings, 2 replies; 3+ messages in thread
From: David Lechner @ 2025-07-10 23:00 UTC (permalink / raw)
To: Jonathan Cameron, Nuno Sá, Andy Shevchenko
Cc: linux-iio, linux-kernel, David Lechner
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>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: accel: bma180: use stack allocated buffer for scan
2025-07-10 23:00 [PATCH] iio: accel: bma180: use stack allocated buffer for scan David Lechner
@ 2025-07-11 6:29 ` Andy Shevchenko
2025-07-13 14:13 ` Jonathan Cameron
1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2025-07-11 6:29 UTC (permalink / raw)
To: David Lechner
Cc: Jonathan Cameron, Nuno Sá, Andy Shevchenko, linux-iio,
linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: accel: bma180: use stack allocated buffer for scan
2025-07-10 23:00 [PATCH] iio: accel: bma180: use stack allocated buffer for scan David Lechner
2025-07-11 6:29 ` Andy Shevchenko
@ 2025-07-13 14:13 ` Jonathan Cameron
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2025-07-13 14:13 UTC (permalink / raw)
To: David Lechner; +Cc: Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel
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,
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-13 14:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-10 23:00 [PATCH] iio: accel: bma180: use stack allocated buffer for scan David Lechner
2025-07-11 6:29 ` Andy Shevchenko
2025-07-13 14:13 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).