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.

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/das800.c | 51 +++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/comedi/drivers/das800.c 
b/drivers/staging/comedi/drivers/das800.c
index ef5f65f..14420e0 100644
--- a/drivers/staging/comedi/drivers/das800.c
+++ b/drivers/staging/comedi/drivers/das800.c
@@ -300,6 +300,33 @@ static int das800_cancel(struct comedi_device *dev, struct 
comedi_subdevice *s)
        return 0;
 }
 
+static int das800_ai_check_chanlist(struct comedi_device *dev,
+                                   struct comedi_subdevice *s,
+                                   struct comedi_cmd *cmd)
+{
+       unsigned int chan0 = CR_CHAN(cmd->chanlist[0]);
+       unsigned int range0 = CR_RANGE(cmd->chanlist[0]);
+       int i;
+
+       for (i = 1; i < cmd->chanlist_len; i++) {
+               unsigned int chan = CR_CHAN(cmd->chanlist[i]);
+               unsigned int range = CR_RANGE(cmd->chanlist[i]);
+
+               if (chan != (chan0 + i) % s->n_chan) {
+                       dev_err(dev->class_dev,
+                               "chanlist must be consecutive, counting 
upwards\n");
+                       return -EINVAL;
+               }
+
+               if (range != range0) {
+                       dev_err(dev->class_dev,
+                               "chanlist must all have the same range\n");
+                       return -EINVAL;
+               }
+       }
+       return 0;
+}
+
 static int das800_ai_do_cmdtest(struct comedi_device *dev,
                                struct comedi_subdevice *s,
                                struct comedi_cmd *cmd)
@@ -365,27 +392,9 @@ static int das800_ai_do_cmdtest(struct comedi_device *dev,
        if (err)
                return 4;
 
-       /*  check channel/gain list against card's limitations */
-       if (cmd->chanlist) {
-               unsigned int chan = CR_CHAN(cmd->chanlist[0]);
-               unsigned int range = CR_RANGE(cmd->chanlist[0]);
-               unsigned int next;
-               int i;
-
-               for (i = 1; i < cmd->chanlist_len; i++) {
-                       next = cmd->chanlist[i];
-                       if (CR_CHAN(next) != (chan + i) % N_CHAN_AI) {
-                               dev_err(dev->class_dev,
-                                       "chanlist must be consecutive, counting 
upwards\n");
-                               err++;
-                       }
-                       if (CR_RANGE(next) != range) {
-                               dev_err(dev->class_dev,
-                                       "chanlist must all have the same 
gain\n");
-                               err++;
-                       }
-               }
-       }
+       /* Step 5: check channel list */
+
+       err |= das800_ai_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