Skip to content

Commit 43ece27

Browse files
larsclausenjic23
authored andcommitted
iio:trigger: Add helper function to verify that a trigger belongs to the same device
Some triggers can only be attached to the IIO device that corresponds to the same physical device. Currently each driver that requires this implements its own trigger validation function. Introduce a new helper function called iio_trigger_validate_own_device() that can be used to do this check. Having a common implementation avoids code duplication and unnecessary boiler-plate code. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 38e442f commit 43ece27

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎drivers/iio/industrialio-trigger.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,27 @@ bool iio_trigger_using_own(struct iio_dev *indio_dev)
717717
}
718718
EXPORT_SYMBOL(iio_trigger_using_own);
719719

720+
/**
721+
* iio_trigger_validate_own_device - Check if a trigger and IIO device belong to
722+
* the same device
723+
* @trig: The IIO trigger to check
724+
* @indio_dev: the IIO device to check
725+
*
726+
* This function can be used as the validate_device callback for triggers that
727+
* can only be attached to their own device.
728+
*
729+
* Return: 0 if both the trigger and the IIO device belong to the same
730+
* device, -EINVAL otherwise.
731+
*/
732+
int iio_trigger_validate_own_device(struct iio_trigger *trig,
733+
struct iio_dev *indio_dev)
734+
{
735+
if (indio_dev->dev.parent != trig->dev.parent)
736+
return -EINVAL;
737+
return 0;
738+
}
739+
EXPORT_SYMBOL(iio_trigger_validate_own_device);
740+
720741
void iio_device_register_trigger_consumer(struct iio_dev *indio_dev)
721742
{
722743
indio_dev->groups[indio_dev->groupcounter++] =

‎include/linux/iio/trigger.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ void iio_trigger_free(struct iio_trigger *trig);
170170
*/
171171
bool iio_trigger_using_own(struct iio_dev *indio_dev);
172172

173+
int iio_trigger_validate_own_device(struct iio_trigger *trig,
174+
struct iio_dev *indio_dev);
173175

174176
#else
175177
struct iio_trigger;

0 commit comments

Comments
 (0)