staging: comedi: addi_apci_1564: fix counter code in main driver source
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 10 Nov 2014 23:20:14 +0000 (16:20 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Nov 2014 23:31:33 +0000 (15:31 -0800)
The Rev 1.0 APCI-1564 boards do not have counters.

Fix the code in the main driver source so that the I/O accesses to the
counters do not happen if the devpriv->counters member is not initialized.

This does not fix the code in hwdrv_apci1564.c. That code violates the
comedi API and is currently broken.

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/addi_apci_1564.c

index b74e6c62eb24031bd6cc7bd70195af23f29c96b9..3fb9cc06973dcafbfe7e3e6722ead1a67243a919 100644 (file)
@@ -141,10 +141,12 @@ static int apci1564_reset(struct comedi_device *dev)
        outl(0x0, devpriv->timer + APCI1564_TIMER_CTRL_REG);
        outl(0x0, devpriv->timer + APCI1564_TIMER_RELOAD_REG);
 
-       /* Reset the counter registers */
-       outl(0x0, devpriv->counters + APCI1564_COUNTER_CTRL_REG(0));
-       outl(0x0, devpriv->counters + APCI1564_COUNTER_CTRL_REG(1));
-       outl(0x0, devpriv->counters + APCI1564_COUNTER_CTRL_REG(2));
+       if (devpriv->counters) {
+               /* Reset the counter registers */
+               outl(0x0, devpriv->counters + APCI1564_COUNTER_CTRL_REG(0));
+               outl(0x0, devpriv->counters + APCI1564_COUNTER_CTRL_REG(1));
+               outl(0x0, devpriv->counters + APCI1564_COUNTER_CTRL_REG(2));
+       }
 
        return 0;
 }
@@ -186,22 +188,24 @@ static irqreturn_t apci1564_interrupt(int irq, void *d)
                outl(ctrl, devpriv->timer + APCI1564_TIMER_CTRL_REG);
        }
 
-       for (chan = 0; chan < 4; chan++) {
-               status = inl(devpriv->counters +
-                            APCI1564_COUNTER_IRQ_REG(chan));
-               if (status & 0x01) {
-                       /*  Disable Counter Interrupt */
-                       ctrl = inl(devpriv->counters +
-                                  APCI1564_COUNTER_CTRL_REG(chan));
-                       outl(0x0, devpriv->counters +
-                            APCI1564_COUNTER_CTRL_REG(chan));
-
-                       /* Send a signal to from kernel to user space */
-                       send_sig(SIGIO, devpriv->tsk_current, 0);
-
-                       /*  Enable Counter Interrupt */
-                       outl(ctrl, devpriv->counters +
-                            APCI1564_COUNTER_CTRL_REG(chan));
+       if (devpriv->counters) {
+               for (chan = 0; chan < 4; chan++) {
+                       status = inl(devpriv->counters +
+                                    APCI1564_COUNTER_IRQ_REG(chan));
+                       if (status & 0x01) {
+                               /*  Disable Counter Interrupt */
+                               ctrl = inl(devpriv->counters +
+                                          APCI1564_COUNTER_CTRL_REG(chan));
+                               outl(0x0, devpriv->counters +
+                                         APCI1564_COUNTER_CTRL_REG(chan));
+
+                               /* Send a signal to from kernel to user space */
+                               send_sig(SIGIO, devpriv->tsk_current, 0);
+
+                               /*  Enable Counter Interrupt */
+                               outl(ctrl, devpriv->counters +
+                                          APCI1564_COUNTER_CTRL_REG(chan));
+                       }
                }
        }