Commit 86266452 authored by Oliver Neukum's avatar Oliver Neukum Committed by Greg Kroah-Hartman

USB: Push BKL on open down into the drivers

Straightforward push into the drivers to allow
auditing individual drivers separately
Signed-off-by: default avatarOliver Neukum <oliver@neukum.org>
Acked-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent f9de332e
...@@ -265,9 +265,10 @@ static int hiddev_release(struct inode * inode, struct file * file) ...@@ -265,9 +265,10 @@ static int hiddev_release(struct inode * inode, struct file * file)
static int hiddev_open(struct inode *inode, struct file *file) static int hiddev_open(struct inode *inode, struct file *file)
{ {
struct hiddev_list *list; struct hiddev_list *list;
int res; int res, i;
int i = iminor(inode) - HIDDEV_MINOR_BASE; lock_kernel();
i = iminor(inode) - HIDDEV_MINOR_BASE;
if (i >= HIDDEV_MINORS || i < 0 || !hiddev_table[i]) if (i >= HIDDEV_MINORS || i < 0 || !hiddev_table[i])
return -ENODEV; return -ENODEV;
...@@ -313,10 +314,12 @@ static int hiddev_open(struct inode *inode, struct file *file) ...@@ -313,10 +314,12 @@ static int hiddev_open(struct inode *inode, struct file *file)
usbhid_open(hid); usbhid_open(hid);
} }
unlock_kernel();
return 0; return 0;
bail: bail:
file->private_data = NULL; file->private_data = NULL;
kfree(list); kfree(list);
unlock_kernel();
return res; return res;
} }
......
...@@ -616,10 +616,12 @@ static int dabusb_open (struct inode *inode, struct file *file) ...@@ -616,10 +616,12 @@ static int dabusb_open (struct inode *inode, struct file *file)
{ {
int devnum = iminor(inode); int devnum = iminor(inode);
pdabusb_t s; pdabusb_t s;
int r;
if (devnum < DABUSB_MINOR || devnum >= (DABUSB_MINOR + NRDABUSB)) if (devnum < DABUSB_MINOR || devnum >= (DABUSB_MINOR + NRDABUSB))
return -EIO; return -EIO;
lock_kernel();
s = &dabusb[devnum - DABUSB_MINOR]; s = &dabusb[devnum - DABUSB_MINOR];
dbg("dabusb_open"); dbg("dabusb_open");
...@@ -634,6 +636,7 @@ static int dabusb_open (struct inode *inode, struct file *file) ...@@ -634,6 +636,7 @@ static int dabusb_open (struct inode *inode, struct file *file)
msleep_interruptible(500); msleep_interruptible(500);
if (signal_pending (current)) { if (signal_pending (current)) {
unlock_kernel();
return -EAGAIN; return -EAGAIN;
} }
mutex_lock(&s->mutex); mutex_lock(&s->mutex);
...@@ -641,6 +644,7 @@ static int dabusb_open (struct inode *inode, struct file *file) ...@@ -641,6 +644,7 @@ static int dabusb_open (struct inode *inode, struct file *file)
if (usb_set_interface (s->usbdev, _DABUSB_IF, 1) < 0) { if (usb_set_interface (s->usbdev, _DABUSB_IF, 1) < 0) {
mutex_unlock(&s->mutex); mutex_unlock(&s->mutex);
dev_err(&s->usbdev->dev, "set_interface failed\n"); dev_err(&s->usbdev->dev, "set_interface failed\n");
unlock_kernel();
return -EINVAL; return -EINVAL;
} }
s->opened = 1; s->opened = 1;
...@@ -649,7 +653,9 @@ static int dabusb_open (struct inode *inode, struct file *file) ...@@ -649,7 +653,9 @@ static int dabusb_open (struct inode *inode, struct file *file)
file->f_pos = 0; file->f_pos = 0;
file->private_data = s; file->private_data = s;
return nonseekable_open(inode, file); r = nonseekable_open(inode, file);
unlock_kernel();
return r;
} }
static int dabusb_release (struct inode *inode, struct file *file) static int dabusb_release (struct inode *inode, struct file *file)
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/smp_lock.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/poll.h> #include <linux/poll.h>
...@@ -325,6 +326,7 @@ static int usb_alphatrack_open(struct inode *inode, struct file *file) ...@@ -325,6 +326,7 @@ static int usb_alphatrack_open(struct inode *inode, struct file *file)
int retval = 0; int retval = 0;
struct usb_interface *interface; struct usb_interface *interface;
lock_kernel();
nonseekable_open(inode, file); nonseekable_open(inode, file);
subminor = iminor(inode); subminor = iminor(inode);
...@@ -394,6 +396,7 @@ static int usb_alphatrack_open(struct inode *inode, struct file *file) ...@@ -394,6 +396,7 @@ static int usb_alphatrack_open(struct inode *inode, struct file *file)
unlock_disconnect_exit: unlock_disconnect_exit:
mutex_unlock(&disconnect_mutex); mutex_unlock(&disconnect_mutex);
unlock_kernel();
return retval; return retval;
} }
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/smp_lock.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/poll.h> #include <linux/poll.h>
...@@ -343,6 +344,7 @@ static int usb_tranzport_open(struct inode *inode, struct file *file) ...@@ -343,6 +344,7 @@ static int usb_tranzport_open(struct inode *inode, struct file *file)
int retval = 0; int retval = 0;
struct usb_interface *interface; struct usb_interface *interface;
lock_kernel();
nonseekable_open(inode, file); nonseekable_open(inode, file);
subminor = iminor(inode); subminor = iminor(inode);
...@@ -413,6 +415,7 @@ static int usb_tranzport_open(struct inode *inode, struct file *file) ...@@ -413,6 +415,7 @@ static int usb_tranzport_open(struct inode *inode, struct file *file)
unlock_disconnect_exit: unlock_disconnect_exit:
mutex_unlock(&disconnect_mutex); mutex_unlock(&disconnect_mutex);
unlock_kernel();
return retval; return retval;
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/poll.h> #include <linux/poll.h>
#include <linux/smp_lock.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/usb/cdc.h> #include <linux/usb/cdc.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
...@@ -516,6 +517,7 @@ static int wdm_open(struct inode *inode, struct file *file) ...@@ -516,6 +517,7 @@ static int wdm_open(struct inode *inode, struct file *file)
struct usb_interface *intf; struct usb_interface *intf;
struct wdm_device *desc; struct wdm_device *desc;
lock_kernel();
mutex_lock(&wdm_mutex); mutex_lock(&wdm_mutex);
intf = usb_find_interface(&wdm_driver, minor); intf = usb_find_interface(&wdm_driver, minor);
if (!intf) if (!intf)
...@@ -548,6 +550,7 @@ static int wdm_open(struct inode *inode, struct file *file) ...@@ -548,6 +550,7 @@ static int wdm_open(struct inode *inode, struct file *file)
usb_autopm_put_interface(desc->intf); usb_autopm_put_interface(desc->intf);
out: out:
mutex_unlock(&wdm_mutex); mutex_unlock(&wdm_mutex);
unlock_kernel();
return rv; return rv;
} }
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/lp.h> #include <linux/lp.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/smp_lock.h>
#undef DEBUG #undef DEBUG
#include <linux/usb.h> #include <linux/usb.h>
...@@ -395,6 +396,7 @@ static int usblp_open(struct inode *inode, struct file *file) ...@@ -395,6 +396,7 @@ static int usblp_open(struct inode *inode, struct file *file)
if (minor < 0) if (minor < 0)
return -ENODEV; return -ENODEV;
lock_kernel();
mutex_lock (&usblp_mutex); mutex_lock (&usblp_mutex);
retval = -ENODEV; retval = -ENODEV;
...@@ -434,6 +436,7 @@ static int usblp_open(struct inode *inode, struct file *file) ...@@ -434,6 +436,7 @@ static int usblp_open(struct inode *inode, struct file *file)
} }
out: out:
mutex_unlock (&usblp_mutex); mutex_unlock (&usblp_mutex);
unlock_kernel();
return retval; return retval;
} }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/kref.h> #include <linux/kref.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/smp_lock.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/usb/tmc.h> #include <linux/usb/tmc.h>
...@@ -113,6 +114,7 @@ static int usbtmc_open(struct inode *inode, struct file *filp) ...@@ -113,6 +114,7 @@ static int usbtmc_open(struct inode *inode, struct file *filp)
struct usbtmc_device_data *data; struct usbtmc_device_data *data;
int retval = 0; int retval = 0;
lock_kernel();
intf = usb_find_interface(&usbtmc_driver, iminor(inode)); intf = usb_find_interface(&usbtmc_driver, iminor(inode));
if (!intf) { if (!intf) {
printk(KERN_ERR KBUILD_MODNAME printk(KERN_ERR KBUILD_MODNAME
...@@ -128,6 +130,7 @@ static int usbtmc_open(struct inode *inode, struct file *filp) ...@@ -128,6 +130,7 @@ static int usbtmc_open(struct inode *inode, struct file *filp)
filp->private_data = data; filp->private_data = data;
exit: exit:
unlock_kernel();
return retval; return retval;
} }
......
...@@ -34,7 +34,6 @@ static int usb_open(struct inode * inode, struct file * file) ...@@ -34,7 +34,6 @@ static int usb_open(struct inode * inode, struct file * file)
int err = -ENODEV; int err = -ENODEV;
const struct file_operations *old_fops, *new_fops = NULL; const struct file_operations *old_fops, *new_fops = NULL;
lock_kernel();
down_read(&minor_rwsem); down_read(&minor_rwsem);
c = usb_minors[minor]; c = usb_minors[minor];
...@@ -53,7 +52,6 @@ static int usb_open(struct inode * inode, struct file * file) ...@@ -53,7 +52,6 @@ static int usb_open(struct inode * inode, struct file * file)
fops_put(old_fops); fops_put(old_fops);
done: done:
up_read(&minor_rwsem); up_read(&minor_rwsem);
unlock_kernel();
return err; return err;
} }
......
...@@ -96,6 +96,7 @@ ...@@ -96,6 +96,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/smp_lock.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/fs.h> #include <linux/fs.h>
...@@ -622,6 +623,7 @@ static int mdc800_device_open (struct inode* inode, struct file *file) ...@@ -622,6 +623,7 @@ static int mdc800_device_open (struct inode* inode, struct file *file)
int retval=0; int retval=0;
int errn=0; int errn=0;
lock_kernel();
mutex_lock(&mdc800->io_lock); mutex_lock(&mdc800->io_lock);
if (mdc800->state == NOT_CONNECTED) if (mdc800->state == NOT_CONNECTED)
...@@ -660,6 +662,7 @@ static int mdc800_device_open (struct inode* inode, struct file *file) ...@@ -660,6 +662,7 @@ static int mdc800_device_open (struct inode* inode, struct file *file)
error_out: error_out:
mutex_unlock(&mdc800->io_lock); mutex_unlock(&mdc800->io_lock);
unlock_kernel();
return errn; return errn;
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#ifdef CONFIG_USB_DEBUG #ifdef CONFIG_USB_DEBUG
...@@ -274,6 +275,7 @@ static int adu_open(struct inode *inode, struct file *file) ...@@ -274,6 +275,7 @@ static int adu_open(struct inode *inode, struct file *file)
dbg(2,"%s : enter", __func__); dbg(2,"%s : enter", __func__);
lock_kernel();
subminor = iminor(inode); subminor = iminor(inode);
if ((retval = mutex_lock_interruptible(&adutux_mutex))) { if ((retval = mutex_lock_interruptible(&adutux_mutex))) {
...@@ -332,6 +334,7 @@ static int adu_open(struct inode *inode, struct file *file) ...@@ -332,6 +334,7 @@ static int adu_open(struct inode *inode, struct file *file)
exit_no_device: exit_no_device:
mutex_unlock(&adutux_mutex); mutex_unlock(&adutux_mutex);
exit_no_lock: exit_no_lock:
unlock_kernel();
dbg(2,"%s : leave, return value %d ", __func__, retval); dbg(2,"%s : leave, return value %d ", __func__, retval);
return retval; return retval;
} }
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/kref.h> #include <linux/kref.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
...@@ -623,22 +624,30 @@ static void ftdi_elan_status_work(struct work_struct *work) ...@@ -623,22 +624,30 @@ static void ftdi_elan_status_work(struct work_struct *work)
*/ */
static int ftdi_elan_open(struct inode *inode, struct file *file) static int ftdi_elan_open(struct inode *inode, struct file *file)
{ {
int subminor = iminor(inode); int subminor;
struct usb_interface *interface = usb_find_interface(&ftdi_elan_driver, struct usb_interface *interface;
subminor);
lock_kernel();
subminor = iminor(inode);
interface = usb_find_interface(&ftdi_elan_driver, subminor);
if (!interface) { if (!interface) {
unlock_kernel();
printk(KERN_ERR "can't find device for minor %d\n", subminor); printk(KERN_ERR "can't find device for minor %d\n", subminor);
return -ENODEV; return -ENODEV;
} else { } else {
struct usb_ftdi *ftdi = usb_get_intfdata(interface); struct usb_ftdi *ftdi = usb_get_intfdata(interface);
if (!ftdi) { if (!ftdi) {
unlock_kernel();
return -ENODEV; return -ENODEV;
} else { } else {
if (down_interruptible(&ftdi->sw_lock)) { if (down_interruptible(&ftdi->sw_lock)) {
unlock_kernel();
return -EINTR; return -EINTR;
} else { } else {
ftdi_elan_get_kref(ftdi); ftdi_elan_get_kref(ftdi);
file->private_data = ftdi; file->private_data = ftdi;
unlock_kernel();
return 0; return 0;
} }
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/usb.h> #include <linux/usb.h>
...@@ -226,16 +227,20 @@ static int idmouse_open(struct inode *inode, struct file *file) ...@@ -226,16 +227,20 @@ static int idmouse_open(struct inode *inode, struct file *file)
struct usb_interface *interface; struct usb_interface *interface;
int result; int result;
lock_kernel();
/* get the interface from minor number and driver information */ /* get the interface from minor number and driver information */
interface = usb_find_interface (&idmouse_driver, iminor (inode)); interface = usb_find_interface (&idmouse_driver, iminor (inode));
if (!interface) if (!interface) {
unlock_kernel();
return -ENODEV; return -ENODEV;
}
mutex_lock(&open_disc_mutex); mutex_lock(&open_disc_mutex);
/* get the device information block from the interface */ /* get the device information block from the interface */
dev = usb_get_intfdata(interface); dev = usb_get_intfdata(interface);
if (!dev) { if (!dev) {
mutex_unlock(&open_disc_mutex); mutex_unlock(&open_disc_mutex);
unlock_kernel();
return -ENODEV; return -ENODEV;
} }
...@@ -272,6 +277,7 @@ static int idmouse_open(struct inode *inode, struct file *file) ...@@ -272,6 +277,7 @@ static int idmouse_open(struct inode *inode, struct file *file)
/* unlock this device */ /* unlock this device */
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
unlock_kernel();
return result; return result;
} }
......
...@@ -602,10 +602,12 @@ static int iowarrior_open(struct inode *inode, struct file *file) ...@@ -602,10 +602,12 @@ static int iowarrior_open(struct inode *inode, struct file *file)
dbg("%s", __func__); dbg("%s", __func__);
lock_kernel();
subminor = iminor(inode); subminor = iminor(inode);
interface = usb_find_interface(&iowarrior_driver, subminor); interface = usb_find_interface(&iowarrior_driver, subminor);
if (!interface) { if (!interface) {
unlock_kernel();
err("%s - error, can't find device for minor %d", __func__, err("%s - error, can't find device for minor %d", __func__,
subminor); subminor);
return -ENODEV; return -ENODEV;
...@@ -615,6 +617,7 @@ static int iowarrior_open(struct inode *inode, struct file *file) ...@@ -615,6 +617,7 @@ static int iowarrior_open(struct inode *inode, struct file *file)
dev = usb_get_intfdata(interface); dev = usb_get_intfdata(interface);
if (!dev) { if (!dev) {
mutex_unlock(&iowarrior_open_disc_lock); mutex_unlock(&iowarrior_open_disc_lock);
unlock_kernel();
return -ENODEV; return -ENODEV;
} }
...@@ -641,6 +644,7 @@ static int iowarrior_open(struct inode *inode, struct file *file) ...@@ -641,6 +644,7 @@ static int iowarrior_open(struct inode *inode, struct file *file)
out: out:
mutex_unlock(&dev->mutex); mutex_unlock(&dev->mutex);
unlock_kernel();
return retval; return retval;
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/input.h> #include <linux/input.h>
...@@ -296,12 +297,14 @@ static int ld_usb_open(struct inode *inode, struct file *file) ...@@ -296,12 +297,14 @@ static int ld_usb_open(struct inode *inode, struct file *file)
int retval; int retval;
struct usb_interface *interface; struct usb_interface *interface;
lock_kernel();
nonseekable_open(inode, file); nonseekable_open(inode, file);
subminor = iminor(inode); subminor = iminor(inode);
interface = usb_find_interface(&ld_usb_driver, subminor); interface = usb_find_interface(&ld_usb_driver, subminor);
if (!interface) { if (!interface) {
unlock_kernel();
err("%s - error, can't find device for minor %d\n", err("%s - error, can't find device for minor %d\n",
__func__, subminor); __func__, subminor);
return -ENODEV; return -ENODEV;
...@@ -309,12 +312,16 @@ static int ld_usb_open(struct inode *inode, struct file *file) ...@@ -309,12 +312,16 @@ static int ld_usb_open(struct inode *inode, struct file *file)
dev = usb_get_intfdata(interface); dev = usb_get_intfdata(interface);
if (!dev) if (!dev) {
unlock_kernel();
return -ENODEV; return -ENODEV;
}
/* lock this device */ /* lock this device */
if (mutex_lock_interruptible(&dev->mutex)) if (mutex_lock_interruptible(&dev->mutex)) {
unlock_kernel();
return -ERESTARTSYS; return -ERESTARTSYS;
}
/* allow opening only once */ /* allow opening only once */
if (dev->open_count) { if (dev->open_count) {
...@@ -353,6 +360,7 @@ static int ld_usb_open(struct inode *inode, struct file *file) ...@@ -353,6 +360,7 @@ static int ld_usb_open(struct inode *inode, struct file *file)
unlock_exit: unlock_exit:
mutex_unlock(&dev->mutex); mutex_unlock(&dev->mutex);
unlock_kernel();
return retval; return retval;
} }
......
...@@ -82,6 +82,7 @@ ...@@ -82,6 +82,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/poll.h> #include <linux/poll.h>
...@@ -345,6 +346,7 @@ static int tower_open (struct inode *inode, struct file *file) ...@@ -345,6 +346,7 @@ static int tower_open (struct inode *inode, struct file *file)
dbg(2, "%s: enter", __func__); dbg(2, "%s: enter", __func__);
lock_kernel();
nonseekable_open(inode, file); nonseekable_open(inode, file);
subminor = iminor(inode); subminor = iminor(inode);
...@@ -430,6 +432,7 @@ static int tower_open (struct inode *inode, struct file *file) ...@@ -430,6 +432,7 @@ static int tower_open (struct inode *inode, struct file *file)
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
exit: exit:
unlock_kernel();
dbg(2, "%s: leave, return value %d ", __func__, retval); dbg(2, "%s: leave, return value %d ", __func__, retval);
return retval; return retval;
......
...@@ -77,7 +77,7 @@ static struct rio_usb_data rio_instance; ...@@ -77,7 +77,7 @@ static struct rio_usb_data rio_instance;
static int open_rio(struct inode *inode, struct file *file) static int open_rio(struct inode *inode, struct file *file)
{ {
struct rio_usb_data *rio = &rio_instance; struct rio_usb_data *rio = &rio_instance;
lock_kernel();
mutex_lock(&(rio->lock)); mutex_lock(&(rio->lock));
if (rio->isopen || !rio->present) { if (rio->isopen || !rio->present) {
...@@ -91,6 +91,7 @@ static int open_rio(struct inode *inode, struct file *file) ...@@ -91,6 +91,7 @@ static int open_rio(struct inode *inode, struct file *file)
mutex_unlock(&(rio->lock)); mutex_unlock(&(rio->lock));
dev_info(&rio->rio_dev->dev, "Rio opened.\n"); dev_info(&rio->rio_dev->dev, "Rio opened.\n");
unlock_kernel();
return 0; return 0;
} }
......
...@@ -2416,21 +2416,28 @@ sisusb_open(struct inode *inode, struct file *file) ...@@ -2416,21 +2416,28 @@ sisusb_open(struct inode *inode, struct file *file)
struct usb_interface *interface; struct usb_interface *interface;
int subminor = iminor(inode); int subminor = iminor(inode);
if (!(interface = usb_find_interface(&sisusb_driver, subminor))) lock_kernel();
if (!(interface = usb_find_interface(&sisusb_driver, subminor))) {
unlock_kernel();
return -ENODEV; return -ENODEV;
}
if (!(sisusb = usb_get_intfdata(interface))) if (!(sisusb = usb_get_intfdata(interface))) {
unlock_kernel();
return -ENODEV; return -ENODEV;
}
mutex_lock(&sisusb->lock); mutex_lock(&sisusb->lock);
if (!sisusb->present || !sisusb->ready) { if (!sisusb->present || !sisusb->ready) {
mutex_unlock(&sisusb->lock); mutex_unlock(&sisusb->lock);
unlock_kernel();
return -ENODEV; return -ENODEV;
} }
if (sisusb->isopen) { if (sisusb->isopen) {
mutex_unlock(&sisusb->lock); mutex_unlock(&sisusb->lock);
unlock_kernel();
return -EBUSY; return -EBUSY;
} }
...@@ -2439,11 +2446,13 @@ sisusb_open(struct inode *inode, struct file *file) ...@@ -2439,11 +2446,13 @@ sisusb_open(struct inode *inode, struct file *file)
if (sisusb_init_gfxdevice(sisusb, 0)) { if (sisusb_init_gfxdevice(sisusb, 0)) {
mutex_unlock(&sisusb->lock); mutex_unlock(&sisusb->lock);
dev_err(&sisusb->sisusb_dev->dev, "Failed to initialize device\n"); dev_err(&sisusb->sisusb_dev->dev, "Failed to initialize device\n");
unlock_kernel();
return -EIO; return -EIO;
} }
} else { } else {
mutex_unlock(&sisusb->lock); mutex_unlock(&sisusb->lock);
dev_err(&sisusb->sisusb_dev->dev, "Device not attached to USB 2.0 hub\n"); dev_err(&sisusb->sisusb_dev->dev, "Device not attached to USB 2.0 hub\n");
unlock_kernel();
return -EIO; return -EIO;
} }
} }
...@@ -2456,6 +2465,7 @@ sisusb_open(struct inode *inode, struct file *file) ...@@ -2456,6 +2465,7 @@ sisusb_open(struct inode *inode, struct file *file)
file->private_data = sisusb; file->private_data = sisusb;
mutex_unlock(&sisusb->lock); mutex_unlock(&sisusb->lock);
unlock_kernel();
return 0; return 0;
} }
......
...@@ -74,10 +74,12 @@ static int lcd_open(struct inode *inode, struct file *file) ...@@ -74,10 +74,12 @@ static int lcd_open(struct inode *inode, struct file *file)
struct usb_interface *interface; struct usb_interface *interface;
int subminor, r; int subminor, r;
lock_kernel();
subminor = iminor(inode); subminor = iminor(inode);
interface = usb_find_interface(&lcd_driver, subminor); interface = usb_find_interface(&lcd_driver, subminor);
if (!interface) { if (!interface) {
unlock_kernel();
err ("USBLCD: %s - error, can't find device for minor %d", err ("USBLCD: %s - error, can't find device for minor %d",
__func__, subminor); __func__, subminor);
return -ENODEV; return -ENODEV;
...@@ -87,6 +89,7 @@ static int lcd_open(struct inode *inode, struct file *file) ...@@ -87,6 +89,7 @@ static int lcd_open(struct inode *inode, struct file *file)
dev = usb_get_intfdata(interface); dev = usb_get_intfdata(interface);
if (!dev) { if (!dev) {
mutex_unlock(&open_disc_mutex); mutex_unlock(&open_disc_mutex);
unlock_kernel();
return -ENODEV; return -ENODEV;
} }
...@@ -98,11 +101,13 @@ static int lcd_open(struct inode *inode, struct file *file) ...@@ -98,11 +101,13 @@ static int lcd_open(struct inode *inode, struct file *file)
r = usb_autopm_get_interface(interface); r = usb_autopm_get_interface(interface);
if (r < 0) { if (r < 0) {
kref_put(&dev->kref, lcd_delete); kref_put(&dev->kref, lcd_delete);
unlock_kernel();
return r; return r;
} }
/* save our object in the file's private structure */ /* save our object in the file's private structure */
file->private_data = dev; file->private_data = dev;
unlock_kernel();
return 0; return 0;
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/smp_lock.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/usb.h> #include <linux/usb.h>
...@@ -103,19 +104,23 @@ static int vstusb_open(struct inode *inode, struct file *file) ...@@ -103,19 +104,23 @@ static int vstusb_open(struct inode *inode, struct file *file)
struct vstusb_device *vstdev; struct vstusb_device *vstdev;
struct usb_interface *interface; struct usb_interface *interface;
lock_kernel();
interface = usb_find_interface(&vstusb_driver, iminor(inode)); interface = usb_find_interface(&vstusb_driver, iminor(inode));
if (!interface) { if (!interface) {
printk(KERN_ERR KBUILD_MODNAME printk(KERN_ERR KBUILD_MODNAME
": %s - error, can't find device for minor %d\n", ": %s - error, can't find device for minor %d\n",
__func__, iminor(inode)); __func__, iminor(inode));
unlock_kernel();
return -ENODEV; return -ENODEV;
} }
vstdev = usb_get_intfdata(interface); vstdev = usb_get_intfdata(interface);
if (!vstdev) if (!vstdev) {
unlock_kernel();
return -ENODEV; return -ENODEV;
}
/* lock this device */ /* lock this device */
mutex_lock(&vstdev->lock); mutex_lock(&vstdev->lock);
...@@ -123,6 +128,7 @@ static int vstusb_open(struct inode *inode, struct file *file) ...@@ -123,6 +128,7 @@ static int vstusb_open(struct inode *inode, struct file *file)
/* can only open one time */ /* can only open one time */
if ((!vstdev->present) || (vstdev->isopen)) { if ((!vstdev->present) || (vstdev->isopen)) {
mutex_unlock(&vstdev->lock); mutex_unlock(&vstdev->lock);
unlock_kernel();
return -EBUSY; return -EBUSY;
} }
...@@ -137,6 +143,7 @@ static int vstusb_open(struct inode *inode, struct file *file) ...@@ -137,6 +143,7 @@ static int vstusb_open(struct inode *inode, struct file *file)
dev_dbg(&vstdev->usb_dev->dev, "%s: opened\n", __func__); dev_dbg(&vstdev->usb_dev->dev, "%s: opened\n", __func__);
mutex_unlock(&vstdev->lock); mutex_unlock(&vstdev->lock);
unlock_kernel();
return 0; return 0;
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/kref.h> #include <linux/kref.h>
#include <linux/smp_lock.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/mutex.h> #include <linux/mutex.h>
...@@ -90,6 +91,7 @@ static int skel_open(struct inode *inode, struct file *file) ...@@ -90,6 +91,7 @@ static int skel_open(struct inode *inode, struct file *file)
int subminor; int subminor;
int retval = 0; int retval = 0;
lock_kernel();
subminor = iminor(inode); subminor = iminor(inode);
interface = usb_find_interface(&skel_driver, subminor); interface = usb_find_interface(&skel_driver, subminor);
...@@ -135,6 +137,7 @@ static int skel_open(struct inode *inode, struct file *file) ...@@ -135,6 +137,7 @@ static int skel_open(struct inode *inode, struct file *file)
mutex_unlock(&dev->io_mutex); mutex_unlock(&dev->io_mutex);
exit: exit:
unlock_kernel();
return retval; return retval;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment