iio:trigger: Add helper function to verify that a trigger belongs to the same device
authorLars-Peter Clausen <lars@metafoo.de>
Fri, 23 Sep 2016 15:19:41 +0000 (17:19 +0200)
committerJonathan Cameron <jic23@kernel.org>
Tue, 27 Sep 2016 19:32:55 +0000 (20:32 +0100)
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>
drivers/iio/industrialio-trigger.c
include/linux/iio/trigger.h

index e1e104845e38b223429bf73b504956d99061cd56..978729f6d7c47744d166648c9f8f4a4b490d4efb 100644 (file)
@@ -717,6 +717,27 @@ bool iio_trigger_using_own(struct iio_dev *indio_dev)
 }
 EXPORT_SYMBOL(iio_trigger_using_own);
 
+/**
+ * iio_trigger_validate_own_device - Check if a trigger and IIO device belong to
+ *  the same device
+ * @trig: The IIO trigger to check
+ * @indio_dev: the IIO device to check
+ *
+ * This function can be used as the validate_device callback for triggers that
+ * can only be attached to their own device.
+ *
+ * Return: 0 if both the trigger and the IIO device belong to the same
+ * device, -EINVAL otherwise.
+ */
+int iio_trigger_validate_own_device(struct iio_trigger *trig,
+       struct iio_dev *indio_dev)
+{
+       if (indio_dev->dev.parent != trig->dev.parent)
+               return -EINVAL;
+       return 0;
+}
+EXPORT_SYMBOL(iio_trigger_validate_own_device);
+
 void iio_device_register_trigger_consumer(struct iio_dev *indio_dev)
 {
        indio_dev->groups[indio_dev->groupcounter++] =
index 4f1154f7a33cb6b5d568e78a4d72f67aba6e311e..ea08302f2d7b27967fb1f0947dcede46411f396c 100644 (file)
@@ -170,6 +170,8 @@ void iio_trigger_free(struct iio_trigger *trig);
  */
 bool iio_trigger_using_own(struct iio_dev *indio_dev);
 
+int iio_trigger_validate_own_device(struct iio_trigger *trig,
+                                    struct iio_dev *indio_dev);
 
 #else
 struct iio_trigger;