Corrected test for INSN_WRITE data value exceeding maxdata. It failed on
authorIan Abbott <abbotti@mev.co.uk>
Mon, 14 Jan 2008 12:26:16 +0000 (12:26 +0000)
committerIan Abbott <abbotti@mev.co.uk>
Mon, 14 Jan 2008 12:26:16 +0000 (12:26 +0000)
subdevices that used per-channel maxdata values (maxdata_list).

comedi/comedi_fops.c

index f437b431597ad5dfc68250a2eb8b6d742c18944f..56123a04dd10455220efec759150790f4c9a55ca 100644 (file)
@@ -788,6 +788,8 @@ static int parse_insn(comedi_device * dev, comedi_insn * insn, lsampl_t * data,
                }
        } else {
                /* a subdevice instruction */
+               lsampl_t maxdata;
+
                if (insn->subdev >= dev->n_subdevices) {
                        DPRINTK("subdevice %d out of range\n", insn->subdev);
                        ret = -EINVAL;
@@ -825,9 +827,15 @@ static int parse_insn(comedi_device * dev, comedi_insn * insn, lsampl_t * data,
                        ret = s->insn_read(dev, s, insn, data);
                        break;
                case INSN_WRITE:
+                       maxdata = s->maxdata_list
+                               ? s->maxdata_list[CR_CHAN(insn->chanspec)]
+                               : s->maxdata;
                        for (i = 0; i < insn->n; ++i) {
-                               if (data[i] > s->maxdata)
+                               if (data[i] > maxdata) {
                                        ret = -EINVAL;
+                                       DPRINTK("bad data value(s)\n");
+                                       break;
+                               }
                        }
                        if (ret == 0)
                                ret = s->insn_write(dev, s, insn, data);