me_daq: don't access *data when insn->n == 0
authorIan Abbott <abbotti@mev.co.uk>
Thu, 15 Dec 2011 21:10:21 +0000 (21:10 +0000)
committerIan Abbott <abbotti@mev.co.uk>
Thu, 15 Dec 2011 21:10:21 +0000 (21:10 +0000)
Due to recent change to do_insnlist_ioctl() and do_insn_ioctl(), the
'data' pointer will be NULL when insn->n == 0.  Do not access *data
in this case.

Also for INSN_WRITE on the AO subdevice, write the nth data value in the
loop instead of the 0th data value.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
comedi/drivers/me_daq.c

index a2ef34b969064fb75bede30f60e9281c137cf8c9..e13ebf0a12d2aa90fbca1368b3558b12e2121db4 100644 (file)
@@ -379,6 +379,9 @@ static int me_ai_insn_read(comedi_device * dev,
        int aref = CR_AREF((&insn->chanspec)[0]);
        int i;
 
+       if (insn->n == 0)
+               return 0;
+
        /* stop any running conversion */
        dev_private->control_1 &= 0xFFFC;
        writew(dev_private->control_1, dev_private->me_regbase + ME_CONTROL_1);
@@ -515,9 +518,9 @@ static int me_ao_insn_write(comedi_device * dev,
        /* Set data register */
        for (i = 0; i < insn->n; i++) {
                chan = CR_CHAN((&insn->chanspec)[i]);
-               writew((data[0] & s->maxdata),
+               writew((data[i] & s->maxdata),
                        dev_private->me_regbase + ME_DAC_DATA_A + (chan << 1));
-               dev_private->ao_readback[chan] = (data[0] & s->maxdata);
+               dev_private->ao_readback[chan] = (data[i] & s->maxdata);
        }
 
        /* Update dac with data registers */