diff mbox series

[v2,05/20] iio: introduced iio_push_to_buffers_with_ts() that takes a data_total_len argument.

Message ID 20250406172001.2167607-6-jic23@kernel.org (mailing list archive)
State New
Headers show
Series IIO: Introduce iio_push_to_buffers_with_ts() taking an input buffer length argument. | expand

Commit Message

Jonathan Cameron April 6, 2025, 5:19 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Check that data_total_len argument against iio_dev->scan_bytes.

The size needs to be at least as big as the scan. It can be larger,
which is typical if only part of fixed sized storage is used due to
a subset of channels being enabled.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
v2:
- Rename size to data_total_len to make it clear that it is about
  data but also that it isn't simply the length to be used.
- Added an unlikely marking.
---
 include/linux/iio/buffer.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Andy Shevchenko April 7, 2025, 9:18 a.m. UTC | #1
On Sun, Apr 06, 2025 at 06:19:46PM +0100, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> 
> Check that data_total_len argument against iio_dev->scan_bytes.
> 
> The size needs to be at least as big as the scan. It can be larger,
> which is typical if only part of fixed sized storage is used due to
> a subset of channels being enabled.

...

> +static inline int iio_push_to_buffers_with_ts(struct iio_dev *indio_dev,
> +					      void *data, size_t data_total_len,
> +					      int64_t timestamp)

Do we still need to inherit int64_t type? Can't it be s64 instead?

> +{
> +	if (unlikely(data_total_len < indio_dev->scan_bytes)) {

> +		dev_err(&indio_dev->dev,
> +			"Undersized storage pushed to buffer\n");

One line, even for the fanatics of 80.

> +		return -ENOSPC;
> +	}
> +
> +	return iio_push_to_buffers_with_timestamp(indio_dev, data, timestamp);
> +}
Nuno Sá April 7, 2025, 4:25 p.m. UTC | #2
On Sun, 2025-04-06 at 18:19 +0100, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> 
> Check that data_total_len argument against iio_dev->scan_bytes.
> 
> The size needs to be at least as big as the scan. It can be larger,
> which is typical if only part of fixed sized storage is used due to
> a subset of channels being enabled.
> 
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> v2:
> - Rename size to data_total_len to make it clear that it is about
>   data but also that it isn't simply the length to be used.
> - Added an unlikely marking.
> ---

Would be nice to do what Andy suggests and move to s64... Anyways:

Reviewed-by: Nuno Sá <nuno.sa@analog.com>

>  include/linux/iio/buffer.h | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/include/linux/iio/buffer.h b/include/linux/iio/buffer.h
> index 3b8d618bb3df..49c5347f35ea 100644
> --- a/include/linux/iio/buffer.h
> +++ b/include/linux/iio/buffer.h
> @@ -45,6 +45,19 @@ static inline int iio_push_to_buffers_with_timestamp(struct
> iio_dev *indio_dev,
>  	return iio_push_to_buffers(indio_dev, data);
>  }
>  
> +static inline int iio_push_to_buffers_with_ts(struct iio_dev *indio_dev,
> +					      void *data, size_t
> data_total_len,
> +					      int64_t timestamp)
> +{
> +	if (unlikely(data_total_len < indio_dev->scan_bytes)) {
> +		dev_err(&indio_dev->dev,
> +			"Undersized storage pushed to buffer\n");
> +		return -ENOSPC;
> +	}
> +
> +	return iio_push_to_buffers_with_timestamp(indio_dev, data,
> timestamp);
> +}
> +
>  int iio_push_to_buffers_with_ts_unaligned(struct iio_dev *indio_dev,
>  					  const void *data, size_t data_sz,
>  					  int64_t timestamp);
diff mbox series

Patch

diff --git a/include/linux/iio/buffer.h b/include/linux/iio/buffer.h
index 3b8d618bb3df..49c5347f35ea 100644
--- a/include/linux/iio/buffer.h
+++ b/include/linux/iio/buffer.h
@@ -45,6 +45,19 @@  static inline int iio_push_to_buffers_with_timestamp(struct iio_dev *indio_dev,
 	return iio_push_to_buffers(indio_dev, data);
 }
 
+static inline int iio_push_to_buffers_with_ts(struct iio_dev *indio_dev,
+					      void *data, size_t data_total_len,
+					      int64_t timestamp)
+{
+	if (unlikely(data_total_len < indio_dev->scan_bytes)) {
+		dev_err(&indio_dev->dev,
+			"Undersized storage pushed to buffer\n");
+		return -ENOSPC;
+	}
+
+	return iio_push_to_buffers_with_timestamp(indio_dev, data, timestamp);
+}
+
 int iio_push_to_buffers_with_ts_unaligned(struct iio_dev *indio_dev,
 					  const void *data, size_t data_sz,
 					  int64_t timestamp);