[PATCH 4/7] staging: comedi: comedi_fc: introduce cfc_check_trigger_is_unique
H Hartley Sweeten
hartleys at visionengravers.com
Tue Sep 11 17:48:10 UTC 2012
"Step 2" of each do_cmdtest checks that the trigger sources are
unique by doing something like this for each trigger:
if (cmd->start_src != TRIG_TIMER &&
cmd->start_src != TRIG_FOLLOW &&
cmd->start_src != TRIG_EXT)
err++;
/* Test the remaining triggers similarly */
if (err)
return 2;
Introduce a helper function in comedi_fc to handle this boilerplate.
The drivers can then just do:
err |= cfc_check_trigger_is_unique(cmd->start_src);
/* Test the remaining triggers similarly */
if (err)
return 2;
Signed-off-by: H Hartley Sweeten <hsweeten at visionengravers.com>
Cc: Ian Abbott <abbotti at mev.co.uk>
Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
---
drivers/staging/comedi/drivers/comedi_fc.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/staging/comedi/drivers/comedi_fc.h b/drivers/staging/comedi/drivers/comedi_fc.h
index 1f08391..94481c6 100644
--- a/drivers/staging/comedi/drivers/comedi_fc.h
+++ b/drivers/staging/comedi/drivers/comedi_fc.h
@@ -93,4 +93,16 @@ static inline int cfc_check_trigger_src(unsigned int *src, unsigned int flags)
return 0;
}
+/**
+ * cfc_check_trigger_is_unique() - make sure a trigger source is unique
+ * @src: the trigger source to check
+ */
+static inline int cfc_check_trigger_is_unique(unsigned int src)
+{
+ /* this test is true if more than one _src bit is set */
+ if ((src & (src - 1)) != 0)
+ return -EINVAL;
+ return 0;
+}
+
#endif /* _COMEDI_FC_H */
--
1.7.11
More information about the devel
mailing list