staging: comedi: das16m1: factor out chanlist checking from (*do_cmdtest)
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Wed, 16 Apr 2014 21:19:13 +0000 (14:19 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Apr 2014 17:18:48 +0000 (10:18 -0700)
Step 5 of the (*do_cmdtest) validates that the cmd->chanlist is compatible
with the hardware.

For aesthetics, factor out the step 5 code for the analog input async command
support. Tidy up the factored out code.

To minimize the noise, change the comedi_error(), which is a wrapper around
dev_err(), to dev_dbg().

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/das16m1.c

index 779225831dc0688e5677ab1ef2f5d8dca05f75ab..a9cd21068ea89df337dbecb2e62c29e8837e4813 100644 (file)
@@ -150,11 +150,39 @@ static void munge_sample_array(unsigned short *array, unsigned int num_elements)
                array[i] = munge_sample(array[i]);
 }
 
+static int das16m1_ai_check_chanlist(struct comedi_device *dev,
+                                    struct comedi_subdevice *s,
+                                    struct comedi_cmd *cmd)
+{
+       int i;
+
+       if (cmd->chanlist_len == 1)
+               return 0;
+
+       if ((cmd->chanlist_len % 2) != 0) {
+               dev_dbg(dev->class_dev,
+                       "chanlist must be of even length or length 1\n");
+               return -EINVAL;
+       }
+
+       for (i = 0; i < cmd->chanlist_len; i++) {
+               unsigned int chan = CR_CHAN(cmd->chanlist[i]);
+
+               if ((i % 2) != (chan % 2)) {
+                       dev_dbg(dev->class_dev,
+                                "even/odd channels must go have even/odd chanlist indices\n");
+                       return -EINVAL;
+               }
+       }
+
+       return 0;
+}
+
 static int das16m1_cmd_test(struct comedi_device *dev,
                            struct comedi_subdevice *s, struct comedi_cmd *cmd)
 {
        struct das16m1_private_struct *devpriv = dev->private;
-       unsigned int err = 0, tmp, i;
+       unsigned int err = 0, tmp;
 
        /* Step 1 : check if triggers are trivially valid */
 
@@ -216,22 +244,9 @@ static int das16m1_cmd_test(struct comedi_device *dev,
        if (err)
                return 4;
 
-       /*  check chanlist against board's peculiarities */
-       if (cmd->chanlist && cmd->chanlist_len > 1) {
-               for (i = 0; i < cmd->chanlist_len; i++) {
-                       /*  even/odd channels must go into even/odd queue addresses */
-                       if ((i % 2) != (CR_CHAN(cmd->chanlist[i]) % 2)) {
-                               comedi_error(dev, "bad chanlist:\n"
-                                            " even/odd channels must go have even/odd chanlist indices");
-                               err++;
-                       }
-               }
-               if ((cmd->chanlist_len % 2) != 0) {
-                       comedi_error(dev,
-                                    "chanlist must be of even length or length 1");
-                       err++;
-               }
-       }
+       /* Step 5: check channel list if it exists */
+       if (cmd->chanlist && cmd->chanlist_len > 0)
+               err |= das16m1_ai_check_chanlist(dev, s, cmd);
 
        if (err)
                return 5;