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

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
Loading
Loading
Loading
Loading
+19 −13
Original line number Diff line number Diff line
@@ -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);

	for (i = 0; i < insn->n; i++) {
		/* write to channel */
		val = data[i];
		if (board->layout == LAYOUT_4020) {
		writew(data[0] & 0xff,
			writew(val & 0xff,
			       devpriv->main_iobase + dac_lsb_4020_reg(chan));
		writew((data[0] >> 8) & 0xf,
			writew((val >> 8) & 0xf,
			       devpriv->main_iobase + dac_msb_4020_reg(chan));
		} else {
		writew(data[0], devpriv->main_iobase + dac_convert_reg(chan));
			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,