staging: comedi: me4000: remove 'board' from me4000_ai_insn_read()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Wed, 5 Aug 2015 17:44:42 +0000 (10:44 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Aug 2015 22:03:27 +0000 (15:03 -0700)
The 'board' pointer is only used in this function to verify that the
'chan' is valid for an aref of AREF_DIFF. For differential inputs, the
maximum channel is half the subdevice 'n_chan'. Use that instead and
remove the 'board' variable.

Also, the comedi core does not validate the aref flags. Add a check
to ensure that the subdevice actually supports the AREF_DIFF mode.

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

index d6b7adc19056fd552928b7c91da5b15e6e9971e8..335fafc73a94d2443406044d07e2f948a6fd1a4a 100644 (file)
@@ -436,10 +436,10 @@ static void me4000_reset(struct comedi_device *dev)
   ===========================================================================*/
 
 static int me4000_ai_insn_read(struct comedi_device *dev,
-                              struct comedi_subdevice *subdevice,
-                              struct comedi_insn *insn, unsigned int *data)
+                              struct comedi_subdevice *s,
+                              struct comedi_insn *insn,
+                              unsigned int *data)
 {
-       const struct me4000_board *board = dev->board_ptr;
        int chan = CR_CHAN(insn->chanspec);
        int rang = CR_RANGE(insn->chanspec);
        int aref = CR_AREF(insn->chanspec);
@@ -481,13 +481,19 @@ static int me4000_ai_insn_read(struct comedi_device *dev,
                break;
 
        case AREF_DIFF:
+               if (!(s->subdev_flags && SDF_DIFF)) {
+                       dev_err(dev->class_dev,
+                               "Differential inputs are not available\n");
+                       return -EINVAL;
+               }
+
                if (rang == 0 || rang == 1) {
                        dev_err(dev->class_dev,
                                "Range must be bipolar when aref = diff\n");
                        return -EINVAL;
                }
 
-               if (chan >= board->ai_diff_nchan) {
+               if (chan >= (s->n_chan / 2)) {
                        dev_err(dev->class_dev,
                                "Analog input is not available\n");
                        return -EINVAL;
This page took 0.026228 seconds and 5 git commands to generate.