staging: comedi: don't consider "unmunged" data when becoming non-busy
authorIan Abbott <abbotti@mev.co.uk>
Mon, 12 Oct 2015 16:21:21 +0000 (17:21 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Oct 2015 17:29:48 +0000 (10:29 -0700)
If an asynchronous "read" command is no longer running but the subdevice
is still busy, it becomes non-busy once there is no more data available
in the buffer.  Some or all of the data written to the buffer might not
have been "munged" yet, and it cannot be read until it has been munged
by the writer.  However, since the command is no longer running, we
cannot expect any remaining unmunged data to get munged so we should
ignore it.  Call `comedi_buf_read_n_available()` to check the amount of
munged data available to be read, replacing the call to
`comedi_buf_n_bytes_ready()` which checked the amount of written (but
possibly not yet munged) data available to be read.  This affects both
the "read" file operation (done in `comedi_read()`) and the
`COMEDI_BUFINFO` ioctl handling (done in `do_bufinfo_ioctl()`).  (The
latter is used when data is transferred directly through the mmapped
buffer instead of via the "read" file operation.)

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

index bb2e0ae0e0528654252fc730756cc8daf05c57c1..c74c50a6e52dc9aaf8b29fa7df3fb244878bf01a 100644 (file)
@@ -1146,7 +1146,7 @@ static int do_bufinfo_ioctl(struct comedi_device *dev,
                comedi_buf_read_free(s, bi.bytes_read);
 
                if (comedi_is_subdevice_idle(s) &&
-                   comedi_buf_n_bytes_ready(s) == 0) {
+                   comedi_buf_read_n_available(s) == 0) {
                        do_become_nonbusy(dev, s);
                }
        }
@@ -2571,7 +2571,8 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
                new_s = comedi_file_read_subdevice(file);
                if (dev->attached && old_detach_count == dev->detach_count &&
                    s == new_s && new_s->async == async) {
-                       if (become_nonbusy || comedi_buf_n_bytes_ready(s) == 0)
+                       if (become_nonbusy ||
+                           comedi_buf_read_n_available(s) == 0)
                                do_become_nonbusy(dev, s);
                }
                mutex_unlock(&dev->mutex);