Step 5 of the (*do_cmdtest) validates that the cmd->chanlist is compatible
with the hardware.

Remove the unnecessary step 5 code in the analog output async command support.

For aesthetics, factor out the step 5 code for the "cdio" async command support.
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/ni_mio_common.c | 31 ++++++++++++++++----------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 8a0e3b7..2e26622 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -3304,11 +3304,6 @@ static int ni_ao_cmdtest(struct comedi_device *dev, 
struct comedi_subdevice *s,
        if (err)
                return 4;
 
-       /* step 5: fix up chanlist */
-
-       if (err)
-               return 5;
-
        return 0;
 }
 
@@ -3439,12 +3434,27 @@ static int ni_m_series_dio_insn_bits(struct 
comedi_device *dev,
        return insn->n;
 }
 
+static int ni_cdio_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)
+                       return -EINVAL;
+       }
+
+       return 0;
+}
+
 static int ni_cdio_cmdtest(struct comedi_device *dev,
                           struct comedi_subdevice *s, struct comedi_cmd *cmd)
 {
        int err = 0;
        int tmp;
-       unsigned i;
 
        /* Step 1 : check if triggers are trivially valid */
 
@@ -3484,12 +3494,9 @@ static int ni_cdio_cmdtest(struct comedi_device *dev,
        if (err)
                return 4;
 
-       /* step 5: check chanlist */
-
-       for (i = 0; i < cmd->chanlist_len; ++i) {
-               if (cmd->chanlist[i] != i)
-                       err = 1;
-       }
+       /* Step 5: check channel list if it exists */
+       if (cmd->chanlist && cmd->chanlist_len > 0)
+               err |= ni_cdio_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