Skip to content

Commit

Permalink
staging: comedi: fix oops for USB DAQ devices.
Browse files Browse the repository at this point in the history
This fixes kernel oops when an USB DAQ device is plugged out while it's
communicating with the userspace software.

Signed-off-by: Bernd Porr <berndporr@f2s.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Bernd Porr authored and Greg Kroah-Hartman committed Nov 27, 2011
1 parent 8b78607 commit 3ffab42
Showing 1 changed file with 53 additions and 18 deletions.
71 changes: 53 additions & 18 deletions drivers/staging/comedi/comedi_fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1452,16 +1452,22 @@ 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->f_dentry->d_inode);
struct comedi_device_file_info *dev_file_info =
comedi_get_device_file_info(minor);
struct comedi_device *dev = dev_file_info->device;
struct comedi_async *async = NULL;
unsigned long start = vma->vm_start;
unsigned long size;
int n_pages;
int i;
int retval;
struct comedi_subdevice *s;
struct comedi_device_file_info *dev_file_info;
struct comedi_device *dev;

dev_file_info = comedi_get_device_file_info(minor);
if (dev_file_info == NULL)
return -ENODEV;
dev = dev_file_info->device;
if (dev == NULL)
return -ENODEV;

mutex_lock(&dev->mutex);
if (!dev->attached) {
Expand Down Expand Up @@ -1528,11 +1534,17 @@ 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_device_file_info *dev_file_info =
comedi_get_device_file_info(minor);
struct comedi_device *dev = dev_file_info->device;
struct comedi_subdevice *read_subdev;
struct comedi_subdevice *write_subdev;
struct comedi_device_file_info *dev_file_info;
struct comedi_device *dev;
dev_file_info = comedi_get_device_file_info(minor);

if (dev_file_info == NULL)
return -ENODEV;
dev = dev_file_info->device;
if (dev == NULL)
return -ENODEV;

mutex_lock(&dev->mutex);
if (!dev->attached) {
Expand Down Expand Up @@ -1578,9 +1590,15 @@ 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->f_dentry->d_inode);
struct comedi_device_file_info *dev_file_info =
comedi_get_device_file_info(minor);
struct comedi_device *dev = dev_file_info->device;
struct comedi_device_file_info *dev_file_info;
struct comedi_device *dev;
dev_file_info = comedi_get_device_file_info(minor);

if (dev_file_info == NULL)
return -ENODEV;
dev = dev_file_info->device;
if (dev == NULL)
return -ENODEV;

if (!dev->attached) {
DPRINTK("no driver configured on comedi%i\n", dev->minor);
Expand Down Expand Up @@ -1683,9 +1701,15 @@ 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->f_dentry->d_inode);
struct comedi_device_file_info *dev_file_info =
comedi_get_device_file_info(minor);
struct comedi_device *dev = dev_file_info->device;
struct comedi_device_file_info *dev_file_info;
struct comedi_device *dev;
dev_file_info = comedi_get_device_file_info(minor);

if (dev_file_info == NULL)
return -ENODEV;
dev = dev_file_info->device;
if (dev == NULL)
return -ENODEV;

if (!dev->attached) {
DPRINTK("no driver configured on comedi%i\n", dev->minor);
Expand Down Expand Up @@ -1885,11 +1909,17 @@ static int comedi_open(struct inode *inode, struct file *file)
static int comedi_close(struct inode *inode, struct file *file)
{
const unsigned minor = iminor(inode);
struct comedi_device_file_info *dev_file_info =
comedi_get_device_file_info(minor);
struct comedi_device *dev = dev_file_info->device;
struct comedi_subdevice *s = NULL;
int i;
struct comedi_device_file_info *dev_file_info;
struct comedi_device *dev;
dev_file_info = comedi_get_device_file_info(minor);

if (dev_file_info == NULL)
return -ENODEV;
dev = dev_file_info->device;
if (dev == NULL)
return -ENODEV;

mutex_lock(&dev->mutex);

Expand Down Expand Up @@ -1923,10 +1953,15 @@ static int comedi_close(struct inode *inode, struct file *file)
static int comedi_fasync(int fd, struct file *file, int on)
{
const unsigned minor = iminor(file->f_dentry->d_inode);
struct comedi_device_file_info *dev_file_info =
comedi_get_device_file_info(minor);
struct comedi_device_file_info *dev_file_info;
struct comedi_device *dev;
dev_file_info = comedi_get_device_file_info(minor);

struct comedi_device *dev = dev_file_info->device;
if (dev_file_info == NULL)
return -ENODEV;
dev = dev_file_info->device;
if (dev == NULL)
return -ENODEV;

return fasync_helper(fd, file, on, &dev->async_queue);
}
Expand Down

0 comments on commit 3ffab42

Please sign in to comment.