On 2012-12-19 22:39, H Hartley Sweeten wrote:
Consolidate the local variables 'read_subdev' and 'write_subdev' into a
single local variable 's'.

Use comedi_dev_from_minor() to simplify the return -ENODEV tests.

Use a goto in the !dev->attached test so that the mutex_unlock() call
is in a common place.

Cleanup the formating of the || in the read and write subdevice poll
code.

Signed-off-by: H Hartley Sweeten <[email protected]>
Cc: Ian Abbott <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
---
  drivers/staging/comedi/comedi_fops.c | 49 +++++++++++++++---------------------
  1 file changed, 20 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/comedi/comedi_fops.c 
b/drivers/staging/comedi/comedi_fops.c
index f67b12a..093f403 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -1823,49 +1823,40 @@ static unsigned int comedi_poll(struct file *file, 
poll_table *wait)
  {
        unsigned int mask = 0;
        const unsigned minor = iminor(file->f_dentry->d_inode);
-       struct comedi_subdevice *read_subdev;
-       struct comedi_subdevice *write_subdev;
        struct comedi_file_info *info = comedi_file_info_from_minor(minor);
-       struct comedi_device *dev;
+       struct comedi_device *dev = comedi_dev_from_minor(minor);

Isn't the comedi_dev_from_minor call a bit wasteful here if we have already called comedi_file_info_from_minor? How about a comedi_dev_from_file_info(info) function that can deal with info being NULL, e.g.:

static inline struct comedi_device *
comedi_dev_from_file_info(struct comedi_file_info *info)
{
        return info ? info->device : NULL;
}

Then you could use:

        struct comedi_file_info *info = comedi_file_info_from_minor(minor);
        struct comedi_device *dev = comedi_dev_from_file_info(info);

This also applies to patches 12, 13 and 25 in this series.

+       struct comedi_subdevice *s;

-       if (info == NULL)
-               return -ENODEV;
-       dev = info->device;
-       if (dev == NULL)
+       if (!dev)
                return -ENODEV;

        mutex_lock(&dev->mutex);
+
        if (!dev->attached) {
                DPRINTK("no driver configured on comedi%i\n", dev->minor);
-               mutex_unlock(&dev->mutex);
-               return 0;
+               goto done;
        }

-       mask = 0;
-       read_subdev = comedi_read_subdevice(info);
-       if (read_subdev) {
-               poll_wait(file, &read_subdev->async->wait_head, wait);
-               if (!read_subdev->busy
-                   || comedi_buf_read_n_available(read_subdev->async) > 0
-                   || !(comedi_get_subdevice_runflags(read_subdev) &
-                        SRF_RUNNING)) {
+       s = comedi_read_subdevice(info);
+       if (s) {
+               poll_wait(file, &s->async->wait_head, wait);
+               if (!s->busy || !(comedi_get_subdevice_runflags(s) & 
SRF_RUNNING) ||
+                   comedi_buf_read_n_available(s->async) > 0)
                        mask |= POLLIN | POLLRDNORM;
-               }
        }
-       write_subdev = comedi_write_subdevice(info);
-       if (write_subdev) {
-               poll_wait(file, &write_subdev->async->wait_head, wait);
-               comedi_buf_write_alloc(write_subdev->async,
-                                      write_subdev->async->prealloc_bufsz);
-               if (!write_subdev->busy
-                   || !(comedi_get_subdevice_runflags(write_subdev) &
-                        SRF_RUNNING)
-                   || comedi_buf_write_n_allocated(write_subdev->async) >=
-                   bytes_per_sample(write_subdev->async->subdevice)) {
+
+       s = comedi_write_subdevice(info);
+       if (s) {
+               unsigned int bps = bytes_per_sample(s->async->subdevice);
+
+               poll_wait(file, &s->async->wait_head, wait);
+               comedi_buf_write_alloc(s->async, s->async->prealloc_bufsz);
+               if (!s->busy || !(comedi_get_subdevice_runflags(s) & 
SRF_RUNNING) ||
+                   comedi_buf_write_n_allocated(s->async) >= bps)
                        mask |= POLLOUT | POLLWRNORM;
-               }
        }

+done:
        mutex_unlock(&dev->mutex);
        return mask;
  }



--
-=( Ian Abbott @ MEV Ltd.    E-mail: <[email protected]>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-
_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel

Reply via email to