diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index aced00e5cd107ae03b7c5e4edc81f1135aa711cc..39ed22b802294f6285fdb2ea83cc88ec7c74a51f 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -1576,6 +1576,19 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, 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; @@ -1588,16 +1601,6 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, 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;