On Fri, 19 Mar 2004 19:10:35 +0100
Oliver Neukum <[EMAIL PROTECTED]> wrote:

> Except that you forgot to initialise the semaphore.

Now actually with a patch for 2.4.

--- linux-2.4.26-pre2/drivers/usb/printer.c     2004-02-26 14:09:58.000000000 -0800
+++ linux-2.4.26-pre2-nip/drivers/usb/printer.c 2004-03-19 11:43:50.000000000 -0800
@@ -222,6 +222,7 @@
 static int usblp_set_protocol(struct usblp *usblp, int protocol);
 static int usblp_cache_device_id_string(struct usblp *usblp);
 
+static DECLARE_MUTEX(usblp_sem);       /* locks the existence of usblp's. */
 
 /*
  * Functions for usblp control messages.
@@ -332,7 +333,7 @@
        if (minor < 0 || minor >= USBLP_MINORS)
                return -ENODEV;
 
-       lock_kernel();
+       down (&usblp_sem);
        usblp  = usblp_table[minor];
 
        retval = -ENODEV;
@@ -374,7 +375,7 @@
                }
        }
 out:
-       unlock_kernel();
+       up (&usblp_sem);
        return retval;
 }
 
@@ -404,15 +405,13 @@
 {
        struct usblp *usblp = file->private_data;
 
-       down (&usblp->sem);
-       lock_kernel();
+       down (&usblp_sem);
        usblp->used = 0;
        if (usblp->present) {
                usblp_unlink_urbs(usblp);
-               up(&usblp->sem);
        } else          /* finish cleanup from disconnect */
                usblp_cleanup (usblp);
-       unlock_kernel();
+       up (&usblp_sem);
        return 0;
 }
 
@@ -1101,17 +1100,16 @@
                BUG ();
        }
 
+       down (&usblp_sem);
        down (&usblp->sem);
-       lock_kernel();
        usblp->present = 0;
 
        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