staging: comedi: ni_atmio16d: cleanup atmio16d_ao_insn_write()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 25 Aug 2014 23:04:26 +0000 (16:04 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 30 Aug 2014 20:22:32 +0000 (13:22 -0700)
The comedi core validates the insn->chanspec and data values before
calling the (*insn_write) functions. The 'chan' will always be valid.

Tidy up this function up a bit and remove the unnecessary code.

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

index f1acca6cd12fb10e9cf3d2f6a5d2e5b05e475a62..ed271ca4d9ec112917d2cf3326739c0ec4cdfe5e 100644 (file)
@@ -510,34 +510,32 @@ static int atmio16d_ao_insn_read(struct comedi_device *dev,
 
 static int atmio16d_ao_insn_write(struct comedi_device *dev,
                                  struct comedi_subdevice *s,
-                                 struct comedi_insn *insn, unsigned int *data)
+                                 struct comedi_insn *insn,
+                                 unsigned int *data)
 {
        struct atmio16d_private *devpriv = dev->private;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int reg = (chan) ? DAC1_REG : DAC0_REG;
+       bool munge = false;
        int i;
-       int chan;
-       int d;
 
-       chan = CR_CHAN(insn->chanspec);
+       if (chan == 0 && devpriv->dac0_coding == dac_2comp)
+               munge = true;
+       if (chan == 1 && devpriv->dac1_coding == dac_2comp)
+               munge = true;
 
        for (i = 0; i < insn->n; i++) {
-               d = data[i];
-               switch (chan) {
-               case 0:
-                       if (devpriv->dac0_coding == dac_2comp)
-                               d ^= 0x800;
-                       outw(d, dev->iobase + DAC0_REG);
-                       break;
-               case 1:
-                       if (devpriv->dac1_coding == dac_2comp)
-                               d ^= 0x800;
-                       outw(d, dev->iobase + DAC1_REG);
-                       break;
-               default:
-                       return -EINVAL;
-               }
-               devpriv->ao_readback[chan] = data[i];
+               unsigned int val = data[i];
+
+               devpriv->ao_readback[chan] = val;
+
+               if (munge)
+                       val ^= 0x800;
+
+               outw(val, dev->iobase + reg);
        }
-       return i;
+
+       return insn->n;
 }
 
 static int atmio16d_dio_insn_bits(struct comedi_device *dev,