Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: core: add iio_device_set_parent() helper

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>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Alexandru Ardelean and committed by
Jonathan Cameron
f5d01793 78289b4a

+20
+20
include/linux/iio/iio.h
··· 649 649 return indio_dev ? dev_to_iio_dev(get_device(&indio_dev->dev)) : NULL; 650 650 } 651 651 652 + /** 653 + * iio_device_set_parent() - assign parent device to the IIO device object 654 + * @indio_dev: IIO device structure 655 + * @parent: reference to parent device object 656 + * 657 + * This utility must be called between IIO device allocation 658 + * (via devm_iio_device_alloc()) & IIO device registration 659 + * (via {devm_}iio_device_register()). 660 + * By default, the device allocation will also assign a parent device to 661 + * the IIO device object. In cases where devm_iio_device_alloc() is used, 662 + * sometimes the parent device must be different than the device used to 663 + * manage the allocation. 664 + * In that case, this helper should be used to change the parent, hence the 665 + * requirement to call this between allocation & registration. 666 + **/ 667 + static inline void iio_device_set_parent(struct iio_dev *indio_dev, 668 + struct device *parent) 669 + { 670 + indio_dev->dev.parent = parent; 671 + } 652 672 653 673 /** 654 674 * iio_device_set_drvdata() - Set device driver data