From: Ian Abbott Date: Fri, 14 May 2010 15:29:11 +0000 (+0000) Subject: For write(), don't bother writing data to buffer if command already X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=46ef0fac7ac268420316f183c5a67e7fbab1edee;p=comedi.git For write(), don't bother writing data to buffer if command already finished, as the data won't be used anyway. This allows user code to see the command has finished before it has refilled the buffer completely. --- diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index 9a5e0ea2..a6386675 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -1580,6 +1580,19 @@ static ssize_t comedi_write(struct file *file, const char *buf, size_t nbytes, while (nbytes > 0 && !retval) { set_current_state(TASK_INTERRUPTIBLE); + if (!(comedi_get_subdevice_runflags(s) & SRF_RUNNING)) { + if (count == 0) { + if (comedi_get_subdevice_runflags(s) & + SRF_ERROR) { + retval = -EPIPE; + } else { + retval = 0; + } + do_become_nonbusy(dev, s); + } + break; + } + n = nbytes; m = n; @@ -1594,16 +1607,6 @@ static ssize_t comedi_write(struct file *file, const char *buf, size_t nbytes, n = m; if (n == 0) { - if (!(comedi_get_subdevice_runflags(s) & SRF_RUNNING)) { - if (comedi_get_subdevice_runflags(s) & - SRF_ERROR) { - retval = -EPIPE; - } else { - retval = 0; - } - do_become_nonbusy(dev, s); - break; - } if (file->f_flags & O_NONBLOCK) { retval = -EAGAIN; break;