diff mbox series

[v3,2/5] iio: buffer: add back-ref from iio_buffer to iio_dev

Message ID 20200410141729.82834-3-alexandru.ardelean@analog.com (mailing list archive)
State New, archived
Headers show
Series iio: core,buffer: re-organize chardev creation | expand

Commit Message

Alexandru Ardelean April 10, 2020, 2:17 p.m. UTC
An IIO device will have multiple buffers, but it shouldn't be allowed that
an IIO buffer should belong to more than 1 IIO device.

Once things get moved more from IIO device to the IIO buffer, and an IIO
device will be able to have more than 1 buffer attached, there will be a
need for a back-ref to the IIO device [from the IIO buffer].

This change adds that.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/industrialio-buffer.c | 2 ++
 include/linux/iio/buffer_impl.h   | 3 +++
 2 files changed, 5 insertions(+)

Comments

Jonathan Cameron April 13, 2020, 3:48 p.m. UTC | #1
On Fri, 10 Apr 2020 17:17:26 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> An IIO device will have multiple buffers, but it shouldn't be allowed that
> an IIO buffer should belong to more than 1 IIO device.
> 
> Once things get moved more from IIO device to the IIO buffer, and an IIO
> device will be able to have more than 1 buffer attached, there will be a
> need for a back-ref to the IIO device [from the IIO buffer].
> 
> This change adds that.
> 
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>

Much as I hate circular references, I can't see a way around this one...

> ---
>  drivers/iio/industrialio-buffer.c | 2 ++
>  include/linux/iio/buffer_impl.h   | 3 +++
>  2 files changed, 5 insertions(+)
> 
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index e6fa1a4e135d..f9ffc7762f6c 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -1478,5 +1478,7 @@ void iio_device_attach_buffer(struct iio_dev *indio_dev,
>  			      struct iio_buffer *buffer)
>  {
>  	indio_dev->buffer = iio_buffer_get(buffer);
> +
> +	indio_dev->buffer->indio_dev = indio_dev;
>  }
>  EXPORT_SYMBOL_GPL(iio_device_attach_buffer);
> diff --git a/include/linux/iio/buffer_impl.h b/include/linux/iio/buffer_impl.h
> index 1e7edf6bed96..8fb92250a190 100644
> --- a/include/linux/iio/buffer_impl.h
> +++ b/include/linux/iio/buffer_impl.h
> @@ -69,6 +69,9 @@ struct iio_buffer_access_funcs {
>   * those writing new buffer implementations.
>   */
>  struct iio_buffer {
> +	/** @indio_dev: IIO device to which this buffer belongs to. */
> +	struct iio_dev *indio_dev;
> +
>  	/** @length: Number of datums in buffer. */
>  	unsigned int length;
>
diff mbox series

Patch

diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index e6fa1a4e135d..f9ffc7762f6c 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -1478,5 +1478,7 @@  void iio_device_attach_buffer(struct iio_dev *indio_dev,
 			      struct iio_buffer *buffer)
 {
 	indio_dev->buffer = iio_buffer_get(buffer);
+
+	indio_dev->buffer->indio_dev = indio_dev;
 }
 EXPORT_SYMBOL_GPL(iio_device_attach_buffer);
diff --git a/include/linux/iio/buffer_impl.h b/include/linux/iio/buffer_impl.h
index 1e7edf6bed96..8fb92250a190 100644
--- a/include/linux/iio/buffer_impl.h
+++ b/include/linux/iio/buffer_impl.h
@@ -69,6 +69,9 @@  struct iio_buffer_access_funcs {
  * those writing new buffer implementations.
  */
 struct iio_buffer {
+	/** @indio_dev: IIO device to which this buffer belongs to. */
+	struct iio_dev *indio_dev;
+
 	/** @length: Number of datums in buffer. */
 	unsigned int length;