Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5d670dc authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman
Browse files

staging: comedi: use file->private_data in file operations



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: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 69e2387f
Loading
Loading
Loading
Loading
+8 −30
Original line number Diff line number Diff line
@@ -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) {