staging: comedi: cb_pcidas64: Use insn->n in AO insn_write handler
authorIan Abbott <abbotti@mev.co.uk>
Tue, 30 Oct 2018 14:17:11 +0000 (14:17 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 7 Nov 2018 12:05:38 +0000 (13:05 +0100)
The `insn_write` handler for the AO subdevice (`ao_winsn()` currently
ignores `insn->n` (the number of samples to write) and assumes a single
sample is to be written.  But `insn->n` could be 0, meaning no samples
should be written, in which case `data[0]` is invalid.

Follow the usual Comedi guidelines and change `ao_winsn()` to write the
specified number of samples.  This fixes the assumption that `data[0]`
is valid.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/cb_pcidas64.c

index 631a703b345d18f44ae9fc91538b03ad277458ff..44e5aaf8bae500f1c88140fd0bb79035b0717629 100644 (file)
@@ -3097,8 +3097,10 @@ static int ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
 {
        const struct pcidas64_board *board = dev->board_ptr;
        struct pcidas64_private *devpriv = dev->private;
-       int chan = CR_CHAN(insn->chanspec);
-       int range = CR_RANGE(insn->chanspec);
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int range = CR_RANGE(insn->chanspec);
+       unsigned int val = s->readback[chan];
+       unsigned int i;
 
        /* do some initializing */
        writew(0, devpriv->main_iobase + DAC_CONTROL0_REG);
@@ -3108,20 +3110,24 @@ static int ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
        writew(devpriv->dac_control1_bits,
               devpriv->main_iobase + DAC_CONTROL1_REG);
 
-       /* write to channel */
-       if (board->layout == LAYOUT_4020) {
-               writew(data[0] & 0xff,
-                      devpriv->main_iobase + dac_lsb_4020_reg(chan));
-               writew((data[0] >> 8) & 0xf,
-                      devpriv->main_iobase + dac_msb_4020_reg(chan));
-       } else {
-               writew(data[0], devpriv->main_iobase + dac_convert_reg(chan));
+       for (i = 0; i < insn->n; i++) {
+               /* write to channel */
+               val = data[i];
+               if (board->layout == LAYOUT_4020) {
+                       writew(val & 0xff,
+                              devpriv->main_iobase + dac_lsb_4020_reg(chan));
+                       writew((val >> 8) & 0xf,
+                              devpriv->main_iobase + dac_msb_4020_reg(chan));
+               } else {
+                       writew(val,
+                              devpriv->main_iobase + dac_convert_reg(chan));
+               }
        }
 
-       /* remember output value */
-       s->readback[chan] = data[0];
+       /* remember last output value */
+       s->readback[chan] = val;
 
-       return 1;
+       return insn->n;
 }
 
 static void set_dac_control0_reg(struct comedi_device *dev,