summaryrefslogtreecommitdiff
path: root/drivers/staging/comedi
diff options
context:
space:
mode:
authorH Hartley Sweeten <hartleys@visionengravers.com>2012-11-14 00:48:03 (GMT)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-11-15 00:23:01 (GMT)
commit61ca8bac45ea2fb263b3a7229e00f040df166501 (patch)
treea950eaa17603aa3ece06bd312093495299df90af /drivers/staging/comedi
parent1f168dbdf731dea301a297e2409adc4a54ed6612 (diff)
downloadlinux-fsl-qoriq-61ca8bac45ea2fb263b3a7229e00f040df166501.tar.xz
staging: comedi: comedi_fc.h: introduce new helpers for do_cmdtest step 3
Step 3 of the do_cmdtest functions validates the arguments for the command to be executed. Most of these are simple tests to see if the argument "is" a value, a "min" value, or a "max" value. Each of these tests then clamps the argument to the value if it fails the test. Introduce three new helper functions in comedi_fc.h to handle these tests and remove the boilerplate code from the drivers. The new helper functions are: cfc_check_trigger_arg_is() - argument must be == the value cfc_check_trigger_arg_min() - argument must be >= the value cfc_check_trigger_arg_max() - argument must be <= the value All of these helpers set the argument to the value and return -EINVAL if the validation fails. 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/staging/comedi')
-rw-r--r--drivers/staging/comedi/drivers/comedi_fc.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/drivers/staging/comedi/drivers/comedi_fc.h b/drivers/staging/comedi/drivers/comedi_fc.h
index 94481c6..31afab7 100644
--- a/drivers/staging/comedi/drivers/comedi_fc.h
+++ b/drivers/staging/comedi/drivers/comedi_fc.h
@@ -105,4 +105,48 @@ static inline int cfc_check_trigger_is_unique(unsigned int src)
return 0;
}
+/**
+ * cfc_check_trigger_arg_is() - trivially validate a trigger argument
+ * @arg: pointer to the trigger arg to validate
+ * @val: the value the argument should be
+ */
+static inline int cfc_check_trigger_arg_is(unsigned int *arg, unsigned int val)
+{
+ if (*arg != val) {
+ *arg = val;
+ return -EINVAL;
+ }
+ return 0;
+}
+
+/**
+ * cfc_check_trigger_arg_min() - trivially validate a trigger argument
+ * @arg: pointer to the trigger arg to validate
+ * @val: the minimum value the argument should be
+ */
+static inline int cfc_check_trigger_arg_min(unsigned int *arg,
+ unsigned int val)
+{
+ if (*arg < val) {
+ *arg = val;
+ return -EINVAL;
+ }
+ return 0;
+}
+
+/**
+ * cfc_check_trigger_arg_max() - trivially validate a trigger argument
+ * @arg: pointer to the trigger arg to validate
+ * @val: the maximum value the argument should be
+ */
+static inline int cfc_check_trigger_arg_max(unsigned int *arg,
+ unsigned int val)
+{
+ if (*arg > val) {
+ *arg = val;
+ return -EINVAL;
+ }
+ return 0;
+}
+
#endif /* _COMEDI_FC_H */