From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Matti Vaittinen <mazziesaccount@gmail.com>
Subject: [PATCH v3 19/20] iio: pressure: Use iio_push_to_buffers_with_ts() to provide length for runtime checks.
Date: Sun, 13 Apr 2025 11:34:42 +0100 [thread overview]
Message-ID: <20250413103443.2420727-20-jic23@kernel.org> (raw)
In-Reply-To: <20250413103443.2420727-1-jic23@kernel.org>
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This new function allows us to perform debug checks in the helper to ensure
that the overrun does not occur. Use it in all the simple cases where
either a static buffer or a structure is used in the drivers.
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> # ROHM BM1390
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/pressure/bmp280-core.c | 25 +++++++++++++++----------
drivers/iio/pressure/hid-sensor-press.c | 5 +++--
drivers/iio/pressure/hsc030pa.c | 4 ++--
drivers/iio/pressure/mpl3115.c | 4 ++--
drivers/iio/pressure/rohm-bm1390.c | 3 ++-
drivers/iio/pressure/zpa2326.c | 4 ++--
6 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index d44ab65c94cb..c20cc4a98c9c 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -1142,8 +1142,9 @@ static irqreturn_t bmp280_trigger_handler(int irq, void *p)
chans[0] = comp_press;
chans[1] = comp_temp;
- iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data,
- iio_get_time_ns(indio_dev));
+ iio_push_to_buffers_with_ts(indio_dev, data->sensor_data,
+ sizeof(data->sensor_data),
+ iio_get_time_ns(indio_dev));
out:
iio_trigger_notify_done(indio_dev->trig);
@@ -1273,8 +1274,9 @@ static irqreturn_t bme280_trigger_handler(int irq, void *p)
chans[1] = comp_temp;
chans[2] = comp_humidity;
- iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data,
- iio_get_time_ns(indio_dev));
+ iio_push_to_buffers_with_ts(indio_dev, data->sensor_data,
+ sizeof(data->sensor_data),
+ iio_get_time_ns(indio_dev));
out:
iio_trigger_notify_done(indio_dev->trig);
@@ -1936,8 +1938,9 @@ static irqreturn_t bmp380_trigger_handler(int irq, void *p)
chans[0] = comp_press;
chans[1] = comp_temp;
- iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data,
- iio_get_time_ns(indio_dev));
+ iio_push_to_buffers_with_ts(indio_dev, data->sensor_data,
+ sizeof(data->sensor_data),
+ iio_get_time_ns(indio_dev));
out:
iio_trigger_notify_done(indio_dev->trig);
@@ -2630,8 +2633,9 @@ static irqreturn_t bmp580_trigger_handler(int irq, void *p)
/* Temperature calculations */
memcpy(&data->sensor_data[offset], &data->buf[0], 3);
- iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data,
- iio_get_time_ns(indio_dev));
+ iio_push_to_buffers_with_ts(indio_dev, data->sensor_data,
+ sizeof(data->sensor_data),
+ iio_get_time_ns(indio_dev));
out:
iio_trigger_notify_done(indio_dev->trig);
@@ -2969,8 +2973,9 @@ static irqreturn_t bmp180_trigger_handler(int irq, void *p)
chans[0] = comp_press;
chans[1] = comp_temp;
- iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data,
- iio_get_time_ns(indio_dev));
+ iio_push_to_buffers_with_ts(indio_dev, data->sensor_data,
+ sizeof(data->sensor_data),
+ iio_get_time_ns(indio_dev));
out:
iio_trigger_notify_done(indio_dev->trig);
diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c
index bffeddff5e91..5f1d6abda3e4 100644
--- a/drivers/iio/pressure/hid-sensor-press.c
+++ b/drivers/iio/pressure/hid-sensor-press.c
@@ -176,8 +176,9 @@ static int press_proc_event(struct hid_sensor_hub_device *hsdev,
if (!press_state->timestamp)
press_state->timestamp = iio_get_time_ns(indio_dev);
- iio_push_to_buffers_with_timestamp(
- indio_dev, &press_state->scan, press_state->timestamp);
+ iio_push_to_buffers_with_ts(indio_dev, &press_state->scan,
+ sizeof(press_state->scan),
+ press_state->timestamp);
}
return 0;
diff --git a/drivers/iio/pressure/hsc030pa.c b/drivers/iio/pressure/hsc030pa.c
index 168245818cfe..2d00c0656259 100644
--- a/drivers/iio/pressure/hsc030pa.c
+++ b/drivers/iio/pressure/hsc030pa.c
@@ -314,8 +314,8 @@ static irqreturn_t hsc_trigger_handler(int irq, void *private)
memcpy(&data->scan.chan[0], &data->buffer[0], 2);
memcpy(&data->scan.chan[1], &data->buffer[2], 2);
- iio_push_to_buffers_with_timestamp(indio_dev, &data->scan,
- iio_get_time_ns(indio_dev));
+ iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan),
+ iio_get_time_ns(indio_dev));
error:
iio_trigger_notify_done(indio_dev->trig);
diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c
index 8397155555bd..d6715997f137 100644
--- a/drivers/iio/pressure/mpl3115.c
+++ b/drivers/iio/pressure/mpl3115.c
@@ -191,8 +191,8 @@ static irqreturn_t mpl3115_trigger_handler(int irq, void *p)
}
mutex_unlock(&data->lock);
- iio_push_to_buffers_with_timestamp(indio_dev, buffer,
- iio_get_time_ns(indio_dev));
+ iio_push_to_buffers_with_ts(indio_dev, buffer, sizeof(buffer),
+ iio_get_time_ns(indio_dev));
done:
iio_trigger_notify_done(indio_dev->trig);
diff --git a/drivers/iio/pressure/rohm-bm1390.c b/drivers/iio/pressure/rohm-bm1390.c
index c651ead080df..dac27fd359ad 100644
--- a/drivers/iio/pressure/rohm-bm1390.c
+++ b/drivers/iio/pressure/rohm-bm1390.c
@@ -652,7 +652,8 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p)
}
}
- iio_push_to_buffers_with_timestamp(idev, &data->buf, data->timestamp);
+ iio_push_to_buffers_with_ts(idev, &data->buf, sizeof(data->buf),
+ data->timestamp);
iio_trigger_notify_done(idev->trig);
return IRQ_HANDLED;
diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
index 30f007794f5b..1640aa3717ed 100644
--- a/drivers/iio/pressure/zpa2326.c
+++ b/drivers/iio/pressure/zpa2326.c
@@ -618,8 +618,8 @@ static int zpa2326_fill_sample_buffer(struct iio_dev *indio_dev,
*/
zpa2326_dbg(indio_dev, "filling raw samples buffer");
- iio_push_to_buffers_with_timestamp(indio_dev, &sample,
- private->timestamp);
+ iio_push_to_buffers_with_ts(indio_dev, &sample, sizeof(sample),
+ private->timestamp);
return 0;
}
--
2.49.0
next prev parent reply other threads:[~2025-04-13 10:35 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-13 10:34 [PATCH v3 00/20] IIO: Introduce iio_push_to_buffers_with_ts() taking an input buffer length argument Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 01/20] iio: adc: ad7266: Fix potential timestamp alignment issue Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 02/20] iio: adc: ad7768-1: Fix insufficient alignment of timestamp Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 03/20] iio: adc: dln2: Use aligned_s64 for timestamp Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 04/20] iio: accel: adxl355: Make timestamp 64-bit aligned using aligned_s64 Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 05/20] iio: introduced iio_push_to_buffers_with_ts() that takes a data_total_len argument Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 06/20] iio: dummy: Use a fixed structure to build up scan to push to buffers Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 07/20] iio: dummy: Switch to iio_push_to_buffers_with_ts() and provide size of storage Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 08/20] iio: adc: ti-ads131e08: Use new iio_push_to_buffers_with_ts() to provide length sanity check Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 09/20] iio: adc: Use iio_push_to_buffers_with_ts() to provide length for runtime checks Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 10/20] iio: accel: " Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 11/20] iio: accel: hid: " Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 12/20] iio: chemical: " Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 13/20] iio: temp: maxim-thermocouple: Fix potential lack of DMA safe buffer Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 14/20] iio: temperature: Use iio_push_to_buffers_with_ts() to provide length for runtime checks Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 15/20] iio: resolver: " Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 16/20] iio: proximity: irsd200: Use a struct for scan and iio_push_to_buffers_with_ts() Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 17/20] iio: proximity: Use iio_push_to_buffers_with_ts() to provide length for runtime checks Jonathan Cameron
2025-04-13 10:34 ` [PATCH v3 18/20] iio: pressure: zpa2326: Use aligned_s64 for the timestamp Jonathan Cameron
2025-04-13 10:34 ` Jonathan Cameron [this message]
2025-04-13 10:34 ` [PATCH v3 20/20] iio: magnetometer: Use iio_push_to_buffers_with_ts() to provide length for runtime checks Jonathan Cameron
2025-04-16 23:48 ` [PATCH v3 00/20] IIO: Introduce iio_push_to_buffers_with_ts() taking an input buffer length argument David Lechner
2025-04-18 14:38 ` 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=20250413103443.2420727-20-jic23@kernel.org \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=mazziesaccount@gmail.com \
--cc=nuno.sa@analog.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).