Skip to content

Commit

Permalink
iio: trigger: Add simple trigger_validation helper
Browse files Browse the repository at this point in the history
Some triggers can only be attached to the IIO device that corresponds to
the same physical device. Implement generic helper which can be used as
a validate_trigger callback for such devices.

Suggested-by: Jonathan Cameron <[email protected]>
Signed-off-by: Matti Vaittinen <[email protected]>
Link: https://lore.kernel.org/r/51cd3e3e74a6addf8d333f4a109fb9c5a11086ee.1683541225.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
M-Vaittinen authored and jic23 committed May 23, 2023
1 parent 4bef3ad commit 517985e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion drivers/iio/industrialio-trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ int iio_trigger_attach_poll_func(struct iio_trigger *trig,
* this is the case if the IIO device and the trigger device share the
* same parent device.
*/
if (pf->indio_dev->dev.parent == trig->dev.parent)
if (iio_validate_own_trigger(pf->indio_dev, trig))
trig->attached_own_device = true;

return ret;
Expand Down Expand Up @@ -728,6 +728,26 @@ bool iio_trigger_using_own(struct iio_dev *indio_dev)
}
EXPORT_SYMBOL(iio_trigger_using_own);

/**
* iio_validate_own_trigger - Check if a trigger and IIO device belong to
* the same device
* @idev: the IIO device to check
* @trig: the IIO trigger to check
*
* This function can be used as the validate_trigger 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_validate_own_trigger(struct iio_dev *idev, struct iio_trigger *trig)
{
if (idev->dev.parent != trig->dev.parent)
return -EINVAL;
return 0;
}
EXPORT_SYMBOL_GPL(iio_validate_own_trigger);

/**
* iio_trigger_validate_own_device - Check if a trigger and IIO device belong to
* the same device
Expand Down
1 change: 1 addition & 0 deletions include/linux/iio/trigger.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void iio_trigger_free(struct iio_trigger *trig);
*/
bool iio_trigger_using_own(struct iio_dev *indio_dev);

int iio_validate_own_trigger(struct iio_dev *idev, struct iio_trigger *trig);
int iio_trigger_validate_own_device(struct iio_trigger *trig,
struct iio_dev *indio_dev);

Expand Down

0 comments on commit 517985e

Please sign in to comment.