staging: comedi: comedidev.h: clarify async->event error/cancel detection
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 13 Oct 2014 16:56:08 +0000 (09:56 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Oct 2014 07:47:11 +0000 (15:47 +0800)
Introduce COMEDI_CB_ERROR_MASK and COMEDI_CB_CANCEL_MASK to clarify the
async->events that indicate errors and cancel an async command.

Use the new defines to tidy up and clarify the code.

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/comedi_fops.c
drivers/staging/comedi/comedidev.h
drivers/staging/comedi/drivers.c
drivers/staging/comedi/drivers/amplc_pci230.c

index 224af2b..2fb0f87 100644 (file)
@@ -1555,9 +1555,7 @@ static int do_cmd_ioctl(struct comedi_device *dev,
 
        comedi_buf_reset(s);
 
-       async->cb_mask =
-           COMEDI_CB_EOA | COMEDI_CB_BLOCK | COMEDI_CB_ERROR |
-           COMEDI_CB_OVERFLOW;
+       async->cb_mask = COMEDI_CB_BLOCK | COMEDI_CB_CANCEL_MASK;
        if (async->cmd.flags & CMDF_WAKE_EOS)
                async->cb_mask |= COMEDI_CB_EOS;
 
@@ -2390,14 +2388,14 @@ void comedi_event(struct comedi_device *dev, struct comedi_subdevice *s)
        if (!comedi_is_subdevice_running(s))
                return;
 
-       if (s->
-           async->events & (COMEDI_CB_EOA | COMEDI_CB_ERROR |
-                            COMEDI_CB_OVERFLOW)) {
+       if (s->async->events & COMEDI_CB_CANCEL_MASK)
                runflags_mask |= SRF_RUNNING;
-       }
-       /* remember if an error event has occurred, so an error
-        * can be returned the next time the user does a read() */
-       if (s->async->events & (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW)) {
+
+       /*
+        * Remember if an error event has occurred, so an error
+        * can be returned the next time the user does a read().
+        */
+       if (s->async->events & COMEDI_CB_ERROR_MASK) {
                runflags_mask |= SRF_ERROR;
                runflags |= SRF_ERROR;
        }
index 0b504b1..fb8ff84 100644 (file)
@@ -221,6 +221,9 @@ struct comedi_async {
  * @COMEDI_CB_EOBUF:           DEPRECATED: end of buffer
  * @COMEDI_CB_ERROR:           card error during acquisition
  * @COMEDI_CB_OVERFLOW:                buffer overflow/underflow
+ *
+ * @COMEDI_CB_ERROR_MASK:      events that indicate an error has occurred
+ * @COMEDI_CB_CANCEL_MASK:     events that will cancel an async command
  */
 #define COMEDI_CB_EOS          (1 << 0)
 #define COMEDI_CB_EOA          (1 << 1)
@@ -229,6 +232,9 @@ struct comedi_async {
 #define COMEDI_CB_ERROR                (1 << 4)
 #define COMEDI_CB_OVERFLOW     (1 << 5)
 
+#define COMEDI_CB_ERROR_MASK   (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW)
+#define COMEDI_CB_CANCEL_MASK  (COMEDI_CB_EOA | COMEDI_CB_ERROR_MASK)
+
 struct comedi_driver {
        struct comedi_driver *next;
 
index 859b722..ff2df85 100644 (file)
@@ -375,7 +375,7 @@ unsigned int comedi_handle_events(struct comedi_device *dev,
        if (events == 0)
                return events;
 
-       if (events & (COMEDI_CB_EOA | COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW))
+       if (events & COMEDI_CB_CANCEL_MASK)
                s->cancel(dev, s);
 
        comedi_event(dev, s);
index a04ce6b..a3b34d8 100644 (file)
@@ -1119,7 +1119,6 @@ static bool pci230_handle_ao_fifo(struct comedi_device *dev,
        unsigned short dacstat;
        unsigned int i, n;
        unsigned int events = 0;
-       bool running;
 
        /* Get DAC FIFO status. */
        dacstat = inw(devpriv->daqio + PCI230_DACCON);
@@ -1201,12 +1200,8 @@ static bool pci230_handle_ao_fifo(struct comedi_device *dev,
                        events |= COMEDI_CB_OVERFLOW | COMEDI_CB_ERROR;
                }
        }
-       if (events & (COMEDI_CB_EOA | COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW))
-               running = false;
-       else
-               running = true;
        async->events |= events;
-       return running;
+       return !(async->events & COMEDI_CB_CANCEL_MASK);
 }
 
 static int pci230_ao_inttrig_scan_begin(struct comedi_device *dev,
@@ -2128,8 +2123,7 @@ static void pci230_handle_ai(struct comedi_device *dev,
                events |= COMEDI_CB_BLOCK;
        }
        async->events |= events;
-       if (!(async->events & (COMEDI_CB_EOA | COMEDI_CB_ERROR |
-                              COMEDI_CB_OVERFLOW))) {
+       if (!(async->events & COMEDI_CB_CANCEL_MASK)) {
                /* update FIFO interrupt trigger level */
                pci230_ai_update_fifo_trigger_level(dev, s);
        }