On Fri, 19 Mar 2004 16:14:56 +0100
Oliver Neukum <[EMAIL PROTECTED]> wrote:

> open() is (for char devices) still called under BKL, so this is
> just uselessly eating cycles. And, more importantly, locking
> is not thought through. It is correct by accident currently.

I wouldn't touch it before a replacement is done. I vote for
making the usblp->sem static and using that instead.

What do you think about the attached patch?

-- Pete

--- linux-2.6.5-rc1/drivers/usb/class/usblp.c   2004-03-14 15:44:28.000000000 -0800
+++ linux-2.6.5-rc1-wacom/drivers/usb/class/usblp.c     2004-03-19 09:51:44.000000000 
-0800
@@ -219,6 +219,8 @@
 /* forward reference to make our lives easier */
 extern struct usb_driver usblp_driver;
 
+static struct semaphore usblp_sem;     /* locks the existence of usblp's. */
+
 /*
  * Functions for usblp control messages.
  */
@@ -329,7 +331,7 @@
        if (minor < 0)
                return -ENODEV;
 
-       lock_kernel();
+       down (&usblp_sem);
 
        retval = -ENODEV;
        intf = usb_find_interface(&usblp_driver, minor);
@@ -375,7 +377,7 @@
                }
        }
 out:
-       unlock_kernel();
+       up (&usblp_sem);
        return retval;
 }
 
@@ -405,13 +407,13 @@
 {
        struct usblp *usblp = file->private_data;
 
-       down (&usblp->sem);
+       down (&usblp_sem);
        usblp->used = 0;
        if (usblp->present) {
                usblp_unlink_urbs(usblp);
-               up(&usblp->sem);
        } else          /* finish cleanup from disconnect */
                usblp_cleanup (usblp);
+       up (&usblp_sem);
        return 0;
 }
 
@@ -1123,18 +1125,17 @@
                BUG ();
        }
 
+       down (&usblp_sem);
        down (&usblp->sem);
-       lock_kernel();
        usblp->present = 0;
        usb_set_intfdata (intf, NULL);
 
        usblp_unlink_urbs(usblp);
+       up (&usblp->sem);
 
        if (!usblp->used)
                usblp_cleanup (usblp);
-       else    /* cleanup later, on release */
-               up (&usblp->sem);
-       unlock_kernel();
+       up (&usblp_sem);
 }
 
 static struct usb_device_id usblp_ids [] = {


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to