staging: comedi: vmk80xx: tidy up vmk80xx_cnt_insn_config()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Thu, 22 Jan 2015 00:22:14 +0000 (17:22 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 25 Jan 2015 11:59:14 +0000 (19:59 +0800)
Tidy up this (*insn_config) function to follow the normal format in
comedi drivers.

INSN_CONFIG_RESET instructions do not have any extra parameters (insn->n is
always 1) so the for loop used to write the packet doesn't make any sense.
Remove it and just write the single packet.

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/vmk80xx.c

index d200ad52e7285c57b9af90e667cade9f696af9a0..eb76460e806f3262d9ad17efeb44212cd0cce86e 100644 (file)
@@ -551,41 +551,35 @@ static int vmk80xx_cnt_insn_config(struct comedi_device *dev,
                                   unsigned int *data)
 {
        struct vmk80xx_private *devpriv = dev->private;
-       unsigned int insn_cmd;
-       int chan;
+       unsigned int chan = CR_CHAN(insn->chanspec);
        int cmd;
        int reg;
-       int n;
-
-       insn_cmd = data[0];
-       if (insn_cmd != INSN_CONFIG_RESET)
-               return -EINVAL;
+       int ret;
 
        down(&devpriv->limit_sem);
-
-       chan = CR_CHAN(insn->chanspec);
-
-       if (devpriv->model == VMK8055_MODEL) {
-               if (!chan) {
-                       cmd = VMK8055_CMD_RST_CNT1;
-                       reg = VMK8055_CNT1_REG;
+       switch (data[0]) {
+       case INSN_CONFIG_RESET:
+               if (devpriv->model == VMK8055_MODEL) {
+                       if (!chan) {
+                               cmd = VMK8055_CMD_RST_CNT1;
+                               reg = VMK8055_CNT1_REG;
+                       } else {
+                               cmd = VMK8055_CMD_RST_CNT2;
+                               reg = VMK8055_CNT2_REG;
+                       }
+                       devpriv->usb_tx_buf[reg] = 0x00;
                } else {
-                       cmd = VMK8055_CMD_RST_CNT2;
-                       reg = VMK8055_CNT2_REG;
+                       cmd = VMK8061_CMD_RST_CNT;
                }
-
-               devpriv->usb_tx_buf[reg] = 0x00;
-       } else {
-               cmd = VMK8061_CMD_RST_CNT;
+               ret = vmk80xx_write_packet(dev, cmd);
+               break;
+       default:
+               ret = -EINVAL;
+               break;
        }
-
-       for (n = 0; n < insn->n; n++)
-               if (vmk80xx_write_packet(dev, cmd))
-                       break;
-
        up(&devpriv->limit_sem);
 
-       return n;
+       return ret ? ret : insn->n;
 }
 
 static int vmk80xx_cnt_insn_write(struct comedi_device *dev,