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

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>

authored by

Lars-Peter Clausen and committed by
Jonathan Cameron
43ece27e 38e442fc

+23
+21
drivers/iio/industrialio-trigger.c
··· 717 717 } 718 718 EXPORT_SYMBOL(iio_trigger_using_own); 719 719 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 + 720 741 void iio_device_register_trigger_consumer(struct iio_dev *indio_dev) 721 742 { 722 743 indio_dev->groups[indio_dev->groupcounter++] =
+2
include/linux/iio/trigger.h
··· 170 170 */ 171 171 bool iio_trigger_using_own(struct iio_dev *indio_dev); 172 172 173 + int iio_trigger_validate_own_device(struct iio_trigger *trig, 174 + struct iio_dev *indio_dev); 173 175 174 176 #else 175 177 struct iio_trigger;