diff mbox series

[v2,2/6] iio: core: add iio_device_set_parent() helper

Message ID 20200603114023.175102-3-alexandru.ardelean@analog.com (mailing list archive)
State New, archived
Headers show
Series iio: core: pass parent device as parameter during allocation | expand

Commit Message

Alexandru Ardelean June 3, 2020, 11:40 a.m. UTC
By default, the device allocation will also assign a parent device to the
IIO device object. In cases where devm_iio_device_alloc() is used,
sometimes the parent device must be different than the device used to
manage the allocation.

In that case, this helper should be used to change the parent, hence the
requirement to call this between allocation & registration.

This pattern/requirement is not very common in the IIO space, and it may be
cleaned up later.
But until then, assigning the parent manually between allocation &
registration is slightly easier.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 include/linux/iio/iio.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Jonathan Cameron June 6, 2020, 3:25 p.m. UTC | #1
On Wed, 3 Jun 2020 14:40:19 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> By default, the device allocation will also assign a parent device to the
> IIO device object. In cases where devm_iio_device_alloc() is used,
> sometimes the parent device must be different than the device used to
> manage the allocation.
> 
> In that case, this helper should be used to change the parent, hence the
> requirement to call this between allocation & registration.
> 
> This pattern/requirement is not very common in the IIO space, and it may be
> cleaned up later.
> But until then, assigning the parent manually between allocation &
> registration is slightly easier.
> 
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>

That does the job nicely.

Applied,

Jonathan

> ---
>  include/linux/iio/iio.h | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index 91a69f4751aa..5784f8c9508f 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -649,6 +649,26 @@ static inline struct iio_dev *iio_device_get(struct iio_dev *indio_dev)
>  	return indio_dev ? dev_to_iio_dev(get_device(&indio_dev->dev)) : NULL;
>  }
>  
> +/**
> + * iio_device_set_parent() - assign parent device to the IIO device object
> + * @indio_dev: 		IIO device structure
> + * @parent:		reference to parent device object
> + *
> + * This utility must be called between IIO device allocation
> + * (via devm_iio_device_alloc()) & IIO device registration
> + * (via {devm_}iio_device_register()).
> + * By default, the device allocation will also assign a parent device to
> + * the IIO device object. In cases where devm_iio_device_alloc() is used,
> + * sometimes the parent device must be different than the device used to
> + * manage the allocation.
> + * In that case, this helper should be used to change the parent, hence the
> + * requirement to call this between allocation & registration.
> + **/
> +static inline void iio_device_set_parent(struct iio_dev *indio_dev,
> +					 struct device *parent)
> +{
> +	indio_dev->dev.parent = parent;
> +}
>  
>  /**
>   * iio_device_set_drvdata() - Set device driver data
diff mbox series

Patch

diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 91a69f4751aa..5784f8c9508f 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -649,6 +649,26 @@  static inline struct iio_dev *iio_device_get(struct iio_dev *indio_dev)
 	return indio_dev ? dev_to_iio_dev(get_device(&indio_dev->dev)) : NULL;
 }
 
+/**
+ * iio_device_set_parent() - assign parent device to the IIO device object
+ * @indio_dev: 		IIO device structure
+ * @parent:		reference to parent device object
+ *
+ * This utility must be called between IIO device allocation
+ * (via devm_iio_device_alloc()) & IIO device registration
+ * (via {devm_}iio_device_register()).
+ * By default, the device allocation will also assign a parent device to
+ * the IIO device object. In cases where devm_iio_device_alloc() is used,
+ * sometimes the parent device must be different than the device used to
+ * manage the allocation.
+ * In that case, this helper should be used to change the parent, hence the
+ * requirement to call this between allocation & registration.
+ **/
+static inline void iio_device_set_parent(struct iio_dev *indio_dev,
+					 struct device *parent)
+{
+	indio_dev->dev.parent = parent;
+}
 
 /**
  * iio_device_set_drvdata() - Set device driver data