X-Git-Url: http://pilppa.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fusb%2Fmisc%2Fidmouse.c;h=6da8887538c7ecd0d4359eade1285e8800cbb159;hb=1b29a375fb0b79a11a2d18e7bf5f6da422a35025;hp=15c70bd048c448cf9baa5b4b6d969d57f43cb611;hpb=e0cc09e295f346b7921e921f385fe5213472316a;p=linux-2.6-omap-h63xx.git diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c index 15c70bd048c..6da8887538c 100644 --- a/drivers/usb/misc/idmouse.c +++ b/drivers/usb/misc/idmouse.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -67,6 +66,7 @@ static struct usb_device_id idmouse_table[] = { USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, value, index, NULL, 0, 1000) MODULE_DEVICE_TABLE(usb, idmouse_table); +static DEFINE_MUTEX(open_disc_mutex); /* structure to hold all of our device specific stuff */ struct usb_idmouse { @@ -81,7 +81,7 @@ struct usb_idmouse { int open; /* if the port is open or not */ int present; /* if the device is not disconnected */ - struct semaphore sem; /* locks this structure */ + struct mutex lock; /* locks this structure */ }; @@ -120,9 +120,6 @@ static struct usb_driver idmouse_driver = { .id_table = idmouse_table, }; -/* prevent races between open() and disconnect() */ -static DEFINE_MUTEX(disconnect_mutex); - static int idmouse_create_image(struct usb_idmouse *dev) { int bytes_read; @@ -212,24 +209,22 @@ static int idmouse_open(struct inode *inode, struct file *file) struct usb_interface *interface; int result; - /* prevent disconnects */ - mutex_lock(&disconnect_mutex); - /* get the interface from minor number and driver information */ interface = usb_find_interface (&idmouse_driver, iminor (inode)); - if (!interface) { - mutex_unlock(&disconnect_mutex); + if (!interface) return -ENODEV; - } + + mutex_lock(&open_disc_mutex); /* get the device information block from the interface */ dev = usb_get_intfdata(interface); if (!dev) { - mutex_unlock(&disconnect_mutex); + mutex_unlock(&open_disc_mutex); return -ENODEV; } /* lock this device */ - down(&dev->sem); + mutex_lock(&dev->lock); + mutex_unlock(&open_disc_mutex); /* check if already open */ if (dev->open) { @@ -255,10 +250,7 @@ static int idmouse_open(struct inode *inode, struct file *file) error: /* unlock this device */ - up(&dev->sem); - - /* unlock the disconnect semaphore */ - mutex_unlock(&disconnect_mutex); + mutex_unlock(&dev->lock); return result; } @@ -266,23 +258,19 @@ static int idmouse_release(struct inode *inode, struct file *file) { struct usb_idmouse *dev; - /* prevent a race condition with open() */ - mutex_lock(&disconnect_mutex); - dev = file->private_data; - if (dev == NULL) { - mutex_unlock(&disconnect_mutex); + if (dev == NULL) return -ENODEV; - } + mutex_lock(&open_disc_mutex); /* lock our device */ - down(&dev->sem); + mutex_lock(&dev->lock); /* are we really open? */ if (dev->open <= 0) { - up(&dev->sem); - mutex_unlock(&disconnect_mutex); + mutex_unlock(&dev->lock); + mutex_unlock(&open_disc_mutex); return -ENODEV; } @@ -290,14 +278,13 @@ static int idmouse_release(struct inode *inode, struct file *file) if (!dev->present) { /* the device was unplugged before the file was released */ - up(&dev->sem); + mutex_unlock(&dev->lock); + mutex_unlock(&open_disc_mutex); idmouse_delete(dev); - mutex_unlock(&disconnect_mutex); - return 0; + } else { + mutex_unlock(&dev->lock); + mutex_unlock(&open_disc_mutex); } - - up(&dev->sem); - mutex_unlock(&disconnect_mutex); return 0; } @@ -308,18 +295,18 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count int result; /* lock this object */ - down(&dev->sem); + mutex_lock(&dev->lock); /* verify that the device wasn't unplugged */ if (!dev->present) { - up(&dev->sem); + mutex_unlock(&dev->lock); return -ENODEV; } result = simple_read_from_buffer(buffer, count, ppos, dev->bulk_in_buffer, IMGSIZE); /* unlock the device */ - up(&dev->sem); + mutex_unlock(&dev->lock); return result; } @@ -342,7 +329,7 @@ static int idmouse_probe(struct usb_interface *interface, if (dev == NULL) return -ENOMEM; - init_MUTEX(&dev->sem); + mutex_init(&dev->lock); dev->udev = udev; dev->interface = interface; @@ -392,39 +379,39 @@ static void idmouse_disconnect(struct usb_interface *interface) { struct usb_idmouse *dev; - /* prevent races with open() */ - mutex_lock(&disconnect_mutex); - /* get device structure */ dev = usb_get_intfdata(interface); - usb_set_intfdata(interface, NULL); - - /* lock it */ - down(&dev->sem); /* give back our minor */ usb_deregister_dev(interface, &idmouse_class); + mutex_lock(&open_disc_mutex); + usb_set_intfdata(interface, NULL); + /* lock the device */ + mutex_lock(&dev->lock); + mutex_unlock(&open_disc_mutex); + /* prevent device read, write and ioctl */ dev->present = 0; - /* unlock */ - up(&dev->sem); - /* if the device is opened, idmouse_release will clean this up */ - if (!dev->open) + if (!dev->open) { + mutex_unlock(&dev->lock); idmouse_delete(dev); + } else { + /* unlock */ + mutex_unlock(&dev->lock); + } - mutex_unlock(&disconnect_mutex); - - info("%s disconnected", DRIVER_DESC); + dev_info(&interface->dev, "disconnected\n"); } static int __init usb_idmouse_init(void) { int result; - info(DRIVER_DESC " " DRIVER_VERSION); + printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" + DRIVER_DESC "\n"); /* register this driver with the USB subsystem */ result = usb_register(&idmouse_driver);