[PATCH 43/46] staging: comedi: comedi_fc: introduce cfc_check_trigger_is_unique

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"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@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/comedi_fc.c | 13 +++++++++++++
 drivers/staging/comedi/drivers/comedi_fc.h |  1 +
 2 files changed, 14 insertions(+)

diff --git a/drivers/staging/comedi/drivers/comedi_fc.c b/drivers/staging/comedi/drivers/comedi_fc.c
index a2397b3..e4c525b 100644
--- a/drivers/staging/comedi/drivers/comedi_fc.c
+++ b/drivers/staging/comedi/drivers/comedi_fc.c
@@ -123,6 +123,19 @@ int cfc_check_trigger_src(unsigned int *src, unsigned int flags)
 }
 EXPORT_SYMBOL_GPL(cfc_check_trigger_src);
 
+/**
+ * cfc_check_trigger_is_unique() - make sure a trigger source is unique
+ * @src: the trigger source to check
+ */
+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;
+}
+EXPORT_SYMBOL_GPL(cfc_check_trigger_is_unique);
+
 static int __init comedi_fc_init_module(void)
 {
 	return 0;
diff --git a/drivers/staging/comedi/drivers/comedi_fc.h b/drivers/staging/comedi/drivers/comedi_fc.h
index 0ff9cee..2030d98 100644
--- a/drivers/staging/comedi/drivers/comedi_fc.h
+++ b/drivers/staging/comedi/drivers/comedi_fc.h
@@ -74,5 +74,6 @@ static inline unsigned int cfc_bytes_per_scan(struct comedi_subdevice *subd)
 }
 
 int cfc_check_trigger_src(unsigned int *src, unsigned int flags);
+int cfc_check_trigger_is_unique(unsigned int src);
 
 #endif /* _COMEDI_FC_H */
-- 
1.7.11

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel


[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux