staging: comedi: simplify returned errors for comedi_read()
authorIan Abbott <abbotti@mev.co.uk>
Mon, 12 Oct 2015 16:21:28 +0000 (17:21 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Oct 2015 17:29:48 +0000 (10:29 -0700)
In order to perform a "read" file operation, an asynchronous COMEDI
command in the "read" direction needs to have been set up by the current
file object on the COMEDI "read" subdevice associated with the file
object.  If there is a "read" subdevice, but a command has not been set
up by the file object (or is has been set-up in the wrong direction),
`comedi_read()` currently returns one of two error values `-EINVAL` or
`-EACCES`.  `-EACCES` is returned if the command was set up by a
different subdevice, or somewhat randomly, if a COMEDI "instruction" is
currently being processed.  `-EINVAL` is returned in other cases.
Simplify it by returning `-EINVAL` for all these cases.

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 190592ad092160fa1d96e541fb983701920e8c95..466dc95d5611739c87f0d1a082843e3bdc1b49cd 100644 (file)
@@ -2480,15 +2480,7 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
        async = s->async;
        if (!nbytes)
                goto out;
-       if (!s->busy) {
-               retval = -EINVAL;
-               goto out;
-       }
-       if (s->busy != file) {
-               retval = -EACCES;
-               goto out;
-       }
-       if (async->cmd.flags & CMDF_WRITE) {
+       if (s->busy != file || (async->cmd.flags & CMDF_WRITE)) {
                retval = -EINVAL;
                goto out;
        }
@@ -2520,15 +2512,8 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
                                retval = -ERESTARTSYS;
                                break;
                        }
-                       if (!s->busy) {
-                               retval = -EINVAL;
-                               break;
-                       }
-                       if (s->busy != file) {
-                               retval = -EACCES;
-                               break;
-                       }
-                       if (async->cmd.flags & CMDF_WRITE) {
+                       if (s->busy != file ||
+                           (async->cmd.flags & CMDF_WRITE)) {
                                retval = -EINVAL;
                                break;
                        }