Commit 13015199 authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: cb_pcidas64: Use insn->n in AO insn_write handler

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: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fafb85b4
......@@ -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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment