Step 5 of the (*do_cmdtest) validates that the chanlist, chan/range/aref/etc,
is compatible with the actual hardware. At this point in the (*do_cmdtest)
the chanlist is valid, due to checks in the core, so the sanity check is not
needed.

For aesthetics, factor the step 5 code into a helper function. Tidy up the
factored out code.

Also, remove the unnecessary chanlist sanity check in Step 3.

Signed-off-by: H Hartley Sweeten <hswee...@visionengravers.com>
Cc: Ian Abbott <abbo...@mev.co.uk>
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
---
 drivers/staging/comedi/drivers/gsc_hpdi.c | 36 ++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/comedi/drivers/gsc_hpdi.c 
b/drivers/staging/comedi/drivers/gsc_hpdi.c
index 08d7655..7cf8459 100644
--- a/drivers/staging/comedi/drivers/gsc_hpdi.c
+++ b/drivers/staging/comedi/drivers/gsc_hpdi.c
@@ -360,12 +360,30 @@ static int gsc_hpdi_cmd(struct comedi_device *dev,
        return 0;
 }
 
+static int gsc_hpdi_check_chanlist(struct comedi_device *dev,
+                                  struct comedi_subdevice *s,
+                                  struct comedi_cmd *cmd)
+{
+       int i;
+
+       for (i = 0; i < cmd->chanlist_len; i++) {
+               unsigned int chan = CR_CHAN(cmd->chanlist[i]);
+
+               if (chan != i) {
+                       /*  XXX could support 8 or 16 channels */
+                       dev_err(dev->class_dev,
+                               "chanlist must be ch 0 to 31 in order\n");
+                       return -EINVAL;
+               }
+       }
+       return 0;
+}
+
 static int gsc_hpdi_cmd_test(struct comedi_device *dev,
                             struct comedi_subdevice *s,
                             struct comedi_cmd *cmd)
 {
        int err = 0;
-       int i;
 
        if (s->io_bits)
                return -EINVAL;
@@ -392,10 +410,6 @@ static int gsc_hpdi_cmd_test(struct comedi_device *dev,
 
        /* Step 3: check if arguments are trivially valid */
 
-       if (!cmd->chanlist_len || !cmd->chanlist) {
-               cmd->chanlist_len = 32;
-               err |= -EINVAL;
-       }
        err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
 
        if (cmd->stop_src == TRIG_COUNT)
@@ -411,17 +425,9 @@ static int gsc_hpdi_cmd_test(struct comedi_device *dev,
        if (err)
                return 4;
 
-       /* step 5: complain about special chanlist considerations */
+       /* Step 5: check channel list */
 
-       for (i = 0; i < cmd->chanlist_len; i++) {
-               if (CR_CHAN(cmd->chanlist[i]) != i) {
-                       /*  XXX could support 8 or 16 channels */
-                       dev_err(dev->class_dev,
-                               "chanlist must be ch 0 to 31 in order");
-                       err |= -EINVAL;
-                       break;
-               }
-       }
+       err |= gsc_hpdi_check_chanlist(dev, s, cmd);
 
        if (err)
                return 5;
-- 
1.8.5.2

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

Reply via email to