From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org
Cc: "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <noname.nuno@gmail.com>,
"Jonathan Cameron" <Jonathan.Cameron@huawei.com>
Subject: [PATCH 02/16] iio: dummy: Use a fixed structure to build up scan to push to buffers.
Date: Sun, 9 Mar 2025 18:20:46 +0000 [thread overview]
Message-ID: <20250309182100.1351128-3-jic23@kernel.org> (raw)
In-Reply-To: <20250309182100.1351128-1-jic23@kernel.org>
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
It has long been discouraged for drivers to make use of iio_dev->scan_bytes
directly as that is an implementation detail of the core. As such our
example driver should definitely not be doing so.
A simple anonymous structure definition suffices here as even though
we have a mixture of signed and unsigned channels only the signed ones
use the full storage so the unsigned channels can used signed types as
well.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/dummy/iio_simple_dummy_buffer.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/dummy/iio_simple_dummy_buffer.c b/drivers/iio/dummy/iio_simple_dummy_buffer.c
index 288880346707..050dd993f012 100644
--- a/drivers/iio/dummy/iio_simple_dummy_buffer.c
+++ b/drivers/iio/dummy/iio_simple_dummy_buffer.c
@@ -46,11 +46,10 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->indio_dev;
int i = 0, j;
- u16 *data;
-
- data = kzalloc(indio_dev->scan_bytes, GFP_KERNEL);
- if (!data)
- goto done;
+ struct {
+ s16 data[ARRAY_SIZE(fakedata)];
+ aligned_s64 timestamp;
+ } scan;
/*
* Three common options here:
@@ -69,14 +68,11 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
* constant table fakedata.
*/
iio_for_each_active_channel(indio_dev, j)
- data[i++] = fakedata[j];
+ scan.data[i++] = fakedata[j];
- iio_push_to_buffers_with_timestamp(indio_dev, data,
+ iio_push_to_buffers_with_timestamp(indio_dev, &scan,
iio_get_time_ns(indio_dev));
- kfree(data);
-
-done:
/*
* Tell the core we are done with this trigger and ready for the
* next one.
--
2.48.1
next prev parent reply other threads:[~2025-03-09 18:21 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-09 18:20 [PATCH 00/16] IIO: Introduce iio_push_to_buffers_with_ts() taking an input buffer length argument Jonathan Cameron
2025-03-09 18:20 ` [PATCH 01/16] iio: introduced iio_push_to_buffers_with_ts() that takes a total_len argument Jonathan Cameron
2025-03-10 8:34 ` Nuno Sá
2025-03-10 20:04 ` Jonathan Cameron
2025-03-10 22:16 ` Nuno Sá
2025-03-09 18:20 ` Jonathan Cameron [this message]
2025-03-10 21:10 ` [PATCH 02/16] iio: dummy: Use a fixed structure to build up scan to push to buffers David Lechner
2025-03-09 18:20 ` [PATCH 03/16] iio: dummy: Switch to iio_push_to_buffers_with_ts() and provide size of storage Jonathan Cameron
2025-03-09 18:20 ` [PATCH 04/16] iio: adc: ti-ads131e08: Use new iio_push_to_buffers_with_ts() to provide length sanity check Jonathan Cameron
2025-03-10 22:07 ` David Lechner
2025-03-09 18:20 ` [PATCH 05/16] iio: adc: Use iio_push_to_buffers_with_ts() to provide length for runtime checks Jonathan Cameron
2025-03-10 21:49 ` David Lechner
2025-04-06 17:02 ` Jonathan Cameron
2025-04-06 17:15 ` David Lechner
2025-03-09 18:20 ` [PATCH 06/16] iio: accel: " Jonathan Cameron
2025-03-10 22:20 ` David Lechner
2025-04-06 17:07 ` Jonathan Cameron
2025-03-09 18:20 ` [PATCH 07/16] iio: accel: hid: " Jonathan Cameron
2025-03-11 18:30 ` David Lechner
2025-03-09 18:20 ` [PATCH 08/16] iio: chemical: " Jonathan Cameron
2025-03-09 18:20 ` [PATCH 09/16] iio: temp: maxim-thermocouple: Fix potential lack of DMA safe buffer Jonathan Cameron
2025-03-09 18:20 ` [PATCH 10/16] iio: temperature: Use iio_push_to_buffers_with_ts() to provide length for runtime checks Jonathan Cameron
2025-03-09 18:20 ` [PATCH 11/16] iio: resolver: " Jonathan Cameron
2025-03-09 18:20 ` [PATCH 12/16] iio: proximity: irsd200: Use a struct for scan and iio_push_to_buffers_with_ts() Jonathan Cameron
2025-03-09 18:20 ` [PATCH 13/16] iio: proximity: Use iio_push_to_buffers_with_ts() to provide length for runtime checks Jonathan Cameron
2025-03-09 18:20 ` [PATCH 14/16] iio: pressure: zpa2326: Use aligned_s64 for the timestamp Jonathan Cameron
2025-03-09 18:20 ` [PATCH 15/16] iio: pressure: Use iio_push_to_buffers_with_ts() to provide length for runtime checks Jonathan Cameron
2025-03-09 18:21 ` [PATCH 16/16] iio: magnetometer: " Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250309182100.1351128-3-jic23@kernel.org \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=noname.nuno@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).