diff options
author | H Hartley Sweeten <hartleys@visionengravers.com> | 2012-09-11 17:47:08 (GMT) |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-09-11 19:11:04 (GMT) |
commit | 43b9778eeb789fbfad3ce66da3bbb3440440fbb8 (patch) | |
tree | aabffb058bfbff6eaca7d6ad010af2503ed62de9 /drivers | |
parent | 13b2663c95f6f30f835ef92ef51c9aff0b3f09d6 (diff) | |
download | linux-43b9778eeb789fbfad3ce66da3bbb3440440fbb8.tar.xz |
staging: comedi: comedi_fc: introduce cfc_check_trigger_src
All of the comedi drivers that support the 'cmd' callback also
require a 'do_cmdtest' callback. The do_cmdtest validates the
comedi_cmd before it is executed.
"Step 1" of each do_cmdtest does a trivial validation of the
trigger sources by doing something like this for each trigger:
int err = 0;
unsigned int tmp;
tmp = cmd->start_src;
src &= TRIG_NOW;
if (!src || tmp != src)
err++;
/* Test the remaining triggers similarly */
if (err)
return 1;
Introduce a helper function in comedi_fc to handle this boilerplate.
The drivers can then just do:
err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
/* Test the remaining triggers similarly */
if (err)
return 1;
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/comedi/drivers/comedi_fc.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/drivers/staging/comedi/drivers/comedi_fc.h b/drivers/staging/comedi/drivers/comedi_fc.h index 4b2cfd3..1f08391 100644 --- a/drivers/staging/comedi/drivers/comedi_fc.h +++ b/drivers/staging/comedi/drivers/comedi_fc.h @@ -73,4 +73,24 @@ static inline unsigned int cfc_bytes_per_scan(struct comedi_subdevice *subd) return num_samples * bytes_per_sample(subd); } +/** + * cfc_check_trigger_src() - trivially validate a comedi_cmd trigger source + * @src: pointer to the trigger source to validate + * @flags: bitmask of valid TRIG_* for the trigger + * + * This is used in "step 1" of the do_cmdtest functions of comedi drivers + * to vaildate the comedi_cmd triggers. The mask of the @src against the + * @flags allows the userspace comedilib to pass all the comedi_cmd + * triggers as TRIG_ANY and get back a bitmask of the valid trigger sources. + */ +static inline int cfc_check_trigger_src(unsigned int *src, unsigned int flags) +{ + unsigned int orig_src = *src; + + *src = orig_src & flags; + if (*src == TRIG_INVALID || *src != orig_src) + return -EINVAL; + return 0; +} + #endif /* _COMEDI_FC_H */ |