For write(), don't bother writing data to buffer if command already
authorIan Abbott <abbotti@mev.co.uk>
Fri, 14 May 2010 15:29:11 +0000 (15:29 +0000)
committerIan Abbott <abbotti@mev.co.uk>
Fri, 14 May 2010 15:29:11 +0000 (15:29 +0000)
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.

comedi/comedi_fops.c

index 9a5e0ea2a6e9095869b13c02af45ff24d1433a6c..a638667547d5ac86cac0bed37765b77716536c35 100644 (file)
@@ -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;