staging: comedi: don't poll_wait on same subdevice twice
authorIan Abbott <abbotti@mev.co.uk>
Fri, 9 Oct 2015 11:26:47 +0000 (12:26 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Oct 2015 17:28:40 +0000 (10:28 -0700)
Comedi subdevices that support asynchronous acquisition commands have a
wait queue head used for blocking reads or writes and for the poll file
operation.  The comedi device may have several subdevices that support
"read" and/or "write" commands, but each open file object has at most
one "read" subdevice and one "write" subdevice.  It's possible (though
rare) for those to be the same subdevice if the subdevice supports
commands in either direction.  In that case, the "poll" file operation
doesn't really need to do a `poll_wait()` on the same subdevice twice.
Although harmless, it wastes a poll table entry.  Check for that, and
avoid it.

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 f341421f16445123324a225d7c952f7550256937..bd124815c06a9b8055f856d10b45c828ceb6ae6b 100644 (file)
@@ -2262,7 +2262,7 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait)
        unsigned int mask = 0;
        struct comedi_file *cfp = file->private_data;
        struct comedi_device *dev = cfp->dev;
-       struct comedi_subdevice *s;
+       struct comedi_subdevice *s, *s_read;
 
        mutex_lock(&dev->mutex);
 
@@ -2272,6 +2272,7 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait)
        }
 
        s = comedi_file_read_subdevice(file);
+       s_read = s;
        if (s && s->async) {
                poll_wait(file, &s->async->wait_head, wait);
                if (!s->busy || !comedi_is_subdevice_running(s) ||
@@ -2284,7 +2285,8 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait)
        if (s && s->async) {
                unsigned int bps = comedi_bytes_per_sample(s);
 
-               poll_wait(file, &s->async->wait_head, wait);
+               if (s != s_read)
+                       poll_wait(file, &s->async->wait_head, wait);
                comedi_buf_write_alloc(s, s->async->prealloc_bufsz);
                if (!s->busy || !comedi_is_subdevice_running(s) ||
                    !(s->async->cmd.flags & CMDF_WRITE) ||