From: Ian Abbott Date: Mon, 12 Oct 2015 16:21:21 +0000 (+0100) Subject: staging: comedi: don't consider "unmunged" data when becoming non-busy X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=09d6b9a9ddbbdbf4e45f553fa4405aeacfd12e47;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git staging: comedi: don't consider "unmunged" data when becoming non-busy 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 Reviewed-by: H Hartley Sweeten Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index bb2e0ae0e052..c74c50a6e52d 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -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);