]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/usb/misc/usblcd.c
USB: option: Add Kyocera KPC680 ids
[linux-2.6-omap-h63xx.git] / drivers / usb / misc / usblcd.c
index 504f7221b0d095e8847b902cc6e8955c6517172f..20777d01db62c4fdd705cde8307d5117e79c24e5 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/errno.h>
+#include <linux/mutex.h>
 #include <asm/uaccess.h>
 #include <linux/usb.h>
 
@@ -34,6 +35,8 @@ static struct usb_device_id id_table [] = {
 };
 MODULE_DEVICE_TABLE (usb, id_table);
 
+static DEFINE_MUTEX(open_disc_mutex);
+
 
 struct usb_lcd {
        struct usb_device *     udev;                   /* init: probe_lcd */
@@ -79,12 +82,16 @@ static int lcd_open(struct inode *inode, struct file *file)
                return -ENODEV;
        }
 
+       mutex_lock(&open_disc_mutex);
        dev = usb_get_intfdata(interface);
-       if (!dev)
+       if (!dev) {
+               mutex_unlock(&open_disc_mutex);
                return -ENODEV;
+       }
 
        /* increment our usage count for the device */
        kref_get(&dev->kref);
+       mutex_unlock(&open_disc_mutex);
 
        /* grab a power reference */
        r = usb_autopm_get_interface(interface);
@@ -176,16 +183,17 @@ static int lcd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u
 static void lcd_write_bulk_callback(struct urb *urb)
 {
        struct usb_lcd *dev;
+       int status = urb->status;
 
        dev = (struct usb_lcd *)urb->context;
 
        /* sync/async unlink faults aren't errors */
-       if (urb->status &&
-           !(urb->status == -ENOENT ||
-             urb->status == -ECONNRESET ||
-              urb->status == -ESHUTDOWN)) {
+       if (status &&
+           !(status == -ENOENT ||
+             status == -ECONNRESET ||
+              status == -ESHUTDOWN)) {
                dbg("USBLCD: %s - nonzero write bulk status received: %d",
-                   __FUNCTION__, urb->status);
+                   __FUNCTION__, status);
        }
 
        /* free up our allocated buffer */
@@ -392,8 +400,10 @@ static void lcd_disconnect(struct usb_interface *interface)
        struct usb_lcd *dev;
         int minor = interface->minor;
 
+       mutex_lock(&open_disc_mutex);
         dev = usb_get_intfdata(interface);
         usb_set_intfdata(interface, NULL);
+       mutex_unlock(&open_disc_mutex);
 
         /* give back our minor */
         usb_deregister_dev(interface, &lcd_class);