Staging: comedi: fix bug with invalid minor number usage.
authorFrank Mori Hess <fmhess@users.sourceforge.net>
Mon, 15 Dec 2008 13:48:47 +0000 (13:48 +0000)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 3 Apr 2009 21:53:52 +0000 (14:53 -0700)
Return error instead of segfaulting if user trys to run comedi_config on
a device file with and invalid minor number.

From: Frank Mori Hess <fmhess@users.sourceforge.net>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: David Schleef <ds@schleef.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/comedi/comedi_fops.c

index 1464f550a5af61fa1359ff61002db20a8f85daa7..fbd3d1c6c64715db47a50e2ca8b5570ae6b3b2e3 100644 (file)
@@ -104,9 +104,13 @@ static int comedi_ioctl(struct inode *inode, struct file *file,
        const unsigned minor = iminor(file->f_dentry->d_inode);
        struct comedi_device_file_info *dev_file_info =
            comedi_get_device_file_info(minor);
-       comedi_device *dev = dev_file_info->device;
+       comedi_device *dev;
        int rc;
 
+       if (dev_file_info == NULL || dev_file_info->device == NULL)
+               return -ENODEV;
+       dev = dev_file_info->device;
+
        mutex_lock(&dev->mutex);
 
        /* Device config is special, because it must work on