staging: comedi: introduce comedi_buf_n_bytes_ready()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Fri, 20 Jun 2014 17:58:28 +0000 (10:58 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2014 00:00:44 +0000 (20:00 -0400)
Introduce an inline helper to return the number of bytes that are
ready to read from the comedi_async buffer. Use the helper in the
comedi drivers that currently do the calculation as part of the
(*poll) operation.

Also, use the helper in comedi_fops where the calculation is used as
part of the subdevice going nonbusy.

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/das16m1.c
drivers/staging/comedi/drivers/das1800.c
drivers/staging/comedi/drivers/ni_mio_common.c
drivers/staging/comedi/drivers/ni_pcidio.c
drivers/staging/comedi/drivers/pcl812.c
drivers/staging/comedi/drivers/pcl816.c

index c54ed42f8310faf5739fa89172b1ee779a253e72..d4904cc50f77ae68e19f0457b832b57c20758d00 100644 (file)
@@ -997,7 +997,7 @@ static int do_bufinfo_ioctl(struct comedi_device *dev,
                comedi_buf_read_free(s, bi.bytes_read);
 
                if (comedi_is_subdevice_idle(s) &&
-                   async->buf_write_count == async->buf_read_count) {
+                   comedi_buf_n_bytes_ready(s) == 0) {
                        do_become_nonbusy(dev, s);
                }
        }
@@ -2303,8 +2303,7 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
                new_s = comedi_read_subdevice(dev, minor);
                if (dev->attached && old_detach_count == dev->detach_count &&
                    s == new_s && new_s->async == async) {
-                       if (become_nonbusy ||
-                           async->buf_read_count - async->buf_write_count == 0)
+                       if (become_nonbusy || comedi_buf_n_bytes_ready(s) == 0)
                                do_become_nonbusy(dev, s);
                }
                mutex_unlock(&dev->mutex);
index 71851bdd4273e75247f6d3f6ed9da48d4fa22a32..83fd1553ff93d5317a3a9ca33efcdd8b38038380 100644 (file)
@@ -400,6 +400,11 @@ static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd)
  */
 int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev);
 
+static inline unsigned int comedi_buf_n_bytes_ready(struct comedi_subdevice *s)
+{
+       return s->async->buf_write_count - s->async->buf_read_count;
+}
+
 unsigned int comedi_buf_write_alloc(struct comedi_subdevice *s, unsigned int n);
 unsigned int comedi_buf_write_free(struct comedi_subdevice *s, unsigned int n);
 
index ec039fbff0f9b1583e5013dc1d2dea443db0db27..c252ad22b1b403117a6b16843e86384a32a9e0c4 100644 (file)
@@ -477,7 +477,7 @@ static int das16m1_poll(struct comedi_device *dev, struct comedi_subdevice *s)
        das16m1_handler(dev, status);
        spin_unlock_irqrestore(&dev->spinlock, flags);
 
-       return s->async->buf_write_count - s->async->buf_read_count;
+       return comedi_buf_n_bytes_ready(s);
 }
 
 static irqreturn_t das16m1_interrupt(int irq, void *d)
index 859519026c4c2f1cf621b4508ac8ba6eb4312efc..b2f8391d5de114232571f7a914fadf34c40f75d9 100644 (file)
@@ -696,7 +696,7 @@ static int das1800_ai_poll(struct comedi_device *dev,
        das1800_ai_handler(dev);
        spin_unlock_irqrestore(&dev->spinlock, flags);
 
-       return s->async->buf_write_count - s->async->buf_read_count;
+       return comedi_buf_n_bytes_ready(s);
 }
 
 static irqreturn_t das1800_interrupt(int irq, void *d)
index 7737749d3b2c64a2233d6b6e043da87a198d8422..b2d6b1d1807db9481e7375f0272e6523c2c29859 100644 (file)
@@ -1878,7 +1878,7 @@ static int ni_ai_poll(struct comedi_device *dev, struct comedi_subdevice *s)
 #else
        ni_sync_ai_dma(dev);
 #endif
-       count = s->async->buf_write_count - s->async->buf_read_count;
+       count = comedi_buf_n_bytes_ready(s);
        spin_unlock_irqrestore(&dev->spinlock, flags);
 
        return count;
index 5fc74d6ff6af55a822b8f59f734d4148d5d584f8..b03105ab0e50a68876630641cc92e09c5d34c509 100644 (file)
@@ -361,7 +361,7 @@ static int ni_pcidio_poll(struct comedi_device *dev, struct comedi_subdevice *s)
        if (devpriv->di_mite_chan)
                mite_sync_input_dma(devpriv->di_mite_chan, s);
        spin_unlock(&devpriv->mite_channel_lock);
-       count = s->async->buf_write_count - s->async->buf_read_count;
+       count = comedi_buf_n_bytes_ready(s);
        spin_unlock_irqrestore(&dev->spinlock, irq_flags);
        return count;
 }
index 4c1b9470647838fae364572b3e339571c5d5d8b0..803e7790538cb3a3d990d18f717f6ac3ff895126 100644 (file)
@@ -985,7 +985,7 @@ static int pcl812_ai_poll(struct comedi_device *dev, struct comedi_subdevice *s)
 
        spin_unlock_irqrestore(&dev->spinlock, flags);
 
-       return s->async->buf_write_count - s->async->buf_read_count;
+       return comedi_buf_n_bytes_ready(s);
 }
 
 static int pcl812_ai_cancel(struct comedi_device *dev,
index d9ca7fe16c96695c054e994c4a8e1b3f147a3292..eda9986d9cf84bd49e220c96347795267249ae4b 100644 (file)
@@ -516,7 +516,7 @@ static int pcl816_ai_poll(struct comedi_device *dev, struct comedi_subdevice *s)
 
        cfc_handle_events(dev, s);
 
-       return s->async->buf_write_count - s->async->buf_read_count;
+       return comedi_buf_n_bytes_ready(s);
 }
 
 static int pcl816_ai_cancel(struct comedi_device *dev,