]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
staging: comedi: use file->private_data in file operations
authorIan Abbott <abbotti@mev.co.uk>
Fri, 8 Nov 2013 15:03:40 +0000 (15:03 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 12 Nov 2013 00:16:45 +0000 (16:16 -0800)
Since the `struct comedi_device` should now be protected from being
freed while an open file object is using it, use the `private_data`
member of the `struct file` to point to it.  Set it in `comedi_open()`
and use it in the other file operation handlers instead of calling
`comedi_dev_from_minor()` and checking the result.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/comedi_fops.c

index 37400e85c41709b8642f8c919d36e67e766cd78b..08aa93a1c87cc23be0899df1b9c0a9a83d5a9330 100644 (file)
@@ -1828,12 +1828,9 @@ static long comedi_unlocked_ioctl(struct file *file, unsigned int cmd,
                                  unsigned long arg)
 {
        const unsigned minor = iminor(file_inode(file));
-       struct comedi_device *dev = comedi_dev_from_minor(minor);
+       struct comedi_device *dev = file->private_data;
        int rc;
 
-       if (!dev)
-               return -ENODEV;
-
        mutex_lock(&dev->mutex);
 
        /* Device config is special, because it must work on
@@ -1964,7 +1961,7 @@ static struct vm_operations_struct comedi_vm_ops = {
 static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
 {
        const unsigned minor = iminor(file_inode(file));
-       struct comedi_device *dev = comedi_dev_from_minor(minor);
+       struct comedi_device *dev = file->private_data;
        struct comedi_subdevice *s;
        struct comedi_async *async;
        unsigned long start = vma->vm_start;
@@ -1973,9 +1970,6 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
        int i;
        int retval;
 
-       if (!dev)
-               return -ENODEV;
-
        mutex_lock(&dev->mutex);
 
        if (!dev->attached) {
@@ -2043,12 +2037,9 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait)
 {
        unsigned int mask = 0;
        const unsigned minor = iminor(file_inode(file));
-       struct comedi_device *dev = comedi_dev_from_minor(minor);
+       struct comedi_device *dev = file->private_data;
        struct comedi_subdevice *s;
 
-       if (!dev)
-               return -ENODEV;
-
        mutex_lock(&dev->mutex);
 
        if (!dev->attached) {
@@ -2088,14 +2079,11 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
        int n, m, count = 0, retval = 0;
        DECLARE_WAITQUEUE(wait, current);
        const unsigned minor = iminor(file_inode(file));
-       struct comedi_device *dev = comedi_dev_from_minor(minor);
+       struct comedi_device *dev = file->private_data;
        bool on_wait_queue = false;
        bool attach_locked;
        unsigned int old_detach_count;
 
-       if (!dev)
-               return -ENODEV;
-
        /* Protect against device detachment during operation. */
        down_read(&dev->attach_lock);
        attach_locked = true;
@@ -2227,14 +2215,11 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
        int n, m, count = 0, retval = 0;
        DECLARE_WAITQUEUE(wait, current);
        const unsigned minor = iminor(file_inode(file));
-       struct comedi_device *dev = comedi_dev_from_minor(minor);
+       struct comedi_device *dev = file->private_data;
        unsigned int old_detach_count;
        bool become_nonbusy = false;
        bool attach_locked;
 
-       if (!dev)
-               return -ENODEV;
-
        /* Protect against device detachment during operation. */
        down_read(&dev->attach_lock);
        attach_locked = true;
@@ -2424,6 +2409,7 @@ static int comedi_open(struct inode *inode, struct file *file)
        }
 
        dev->use_count++;
+       file->private_data = dev;
        rc = 0;
 
 out:
@@ -2435,25 +2421,17 @@ static int comedi_open(struct inode *inode, struct file *file)
 
 static int comedi_fasync(int fd, struct file *file, int on)
 {
-       const unsigned minor = iminor(file_inode(file));
-       struct comedi_device *dev = comedi_dev_from_minor(minor);
-
-       if (!dev)
-               return -ENODEV;
+       struct comedi_device *dev = file->private_data;
 
        return fasync_helper(fd, file, on, &dev->async_queue);
 }
 
 static int comedi_close(struct inode *inode, struct file *file)
 {
-       const unsigned minor = iminor(inode);
-       struct comedi_device *dev = comedi_dev_from_minor(minor);
+       struct comedi_device *dev = file->private_data;
        struct comedi_subdevice *s = NULL;
        int i;
 
-       if (!dev)
-               return -ENODEV;
-
        mutex_lock(&dev->mutex);
 
        if (dev->subdevices) {