staging: comedi: ni_labpc: fix labpc_eeprom_insn_write()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Tue, 26 Mar 2013 17:25:57 +0000 (10:25 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 26 Mar 2013 23:14:51 +0000 (16:14 -0700)
The comedi core expects the (*insn_write) operations to write insn->n
values and return the number of values actually wrote.

Make this function work like the core expects.

As Ian Abbott pointed out, we really only need to write the last value
to the eeprom. The preceding data would be overwritten anyway.

Also, remove the noise about invalid channels.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/ni_labpc.c

index 0afcede602ecf956421fd19ec170b160ab7cf1a9..a9117f77b9b234551e6d7c7687243dc4fee935f9 100644 (file)
@@ -1568,21 +1568,24 @@ static int labpc_eeprom_insn_write(struct comedi_device *dev,
                                   struct comedi_insn *insn,
                                   unsigned int *data)
 {
-       int channel = CR_CHAN(insn->chanspec);
+       unsigned int chan = CR_CHAN(insn->chanspec);
        int ret;
 
-       /*  only allow writes to user area of eeprom */
-       if (channel < 16 || channel > 127) {
-               dev_dbg(dev->class_dev,
-                       "eeprom writes are only allowed to channels 16 through 127 (the pointer and user areas)\n");
+       /* only allow writes to user area of eeprom */
+       if (chan < 16 || chan > 127)
                return -EINVAL;
-       }
 
-       ret = labpc_eeprom_write(dev, channel, data[0]);
-       if (ret < 0)
-               return ret;
+       /*
+        * Only write the last data value to the eeprom. Preceding
+        * data would be overwritten anyway.
+        */
+       if (insn->n > 0) {
+               ret = labpc_eeprom_write(dev, chan, data[insn->n - 1]);
+               if (ret)
+                       return ret;
+       }
 
-       return 1;
+       return insn->n;
 }
 
 static int labpc_eeprom_insn_read(struct comedi_device *dev,