In case anyone is wondering, no, I haven't forgotten.

I continue to sit on the attached patch, because it makes no allowances
for ub. I know that in practice it is not a problem, because a) ub only
serves Transparent protocol devices and 210PU is an 8020i protocol device,
and b) ub is only available in 2.6 at present. But still... The whole idea
is just too revolting.

I think I'll watch how 2.6 turns out and then we'll see.

The attached patch includes both segments for devio.c and devices.c
(the latter being a follow-up from Stuart on the original patch).

-- Pete

diff -urp -X dontdiff linux-2.4.28-pre1/drivers/usb/devices.c 
linux-2.4.28-pre1-usb/drivers/usb/devices.c
--- linux-2.4.28-pre1/drivers/usb/devices.c     2002-11-28 15:53:14.000000000 -0800
+++ linux-2.4.28-pre1-usb/drivers/usb/devices.c 2004-08-24 12:47:09.000000000 -0700
@@ -387,22 +387,31 @@ static char *usb_dump_desc(char *start, 
 
        if (start > end)
                return start;
-               
+
+       /*
+        * Grab device's exclusive_access mutex to prevent its driver or
+        * devio from using this device while we are accessing it.
+        */
+       down (&dev->exclusive_access);
+
        start = usb_dump_device_descriptor(start, end, &dev->descriptor);
 
        if (start > end)
-               return start;
-       
+               goto out;
+
        start = usb_dump_device_strings (start, end, dev);
        
        for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
                if (start > end)
-                       return start;
+                       goto out;
                start = usb_dump_config(dev->speed,
                                start, end, dev->config + i,
                                /* active ? */
                                (dev->config + i) == dev->actconfig);
        }
+
+out:
+       up (&dev->exclusive_access);
        return start;
 }
 
diff -urp -X dontdiff linux-2.4.28-pre1/drivers/usb/devio.c 
linux-2.4.28-pre1-usb/drivers/usb/devio.c
--- linux-2.4.28-pre1/drivers/usb/devio.c       2004-08-24 12:38:51.000000000 -0700
+++ linux-2.4.28-pre1-usb/drivers/usb/devio.c   2004-08-24 12:46:22.000000000 -0700
@@ -1158,6 +1158,13 @@ static int usbdev_ioctl(struct inode *in
                up_read(&ps->devsem);
                return -ENODEV;
        }
+
+       /*
+        * grab device's exclusive_access mutex to prevent its driver from
+        * using this device while it is being accessed by us.
+        */
+       down(&ps->dev->exclusive_access);
+
        switch (cmd) {
        case USBDEVFS_CONTROL:
                ret = proc_control(ps, (void *)arg);
@@ -1237,6 +1244,7 @@ static int usbdev_ioctl(struct inode *in
                ret = proc_ioctl(ps, (void *) arg);
                break;
        }
+       up(&ps->dev->exclusive_access);
        up_read(&ps->devsem);
        if (ret >= 0)
                inode->i_atime = CURRENT_TIME;
diff -urp -X dontdiff linux-2.4.28-pre1/drivers/usb/storage/transport.c 
linux-2.4.28-pre1-usb/drivers/usb/storage/transport.c
--- linux-2.4.28-pre1/drivers/usb/storage/transport.c   2004-02-26 14:09:59.000000000 
-0800
+++ linux-2.4.28-pre1-usb/drivers/usb/storage/transport.c       2004-08-24 
12:46:22.000000000 -0700
@@ -627,8 +627,17 @@ void usb_stor_invoke_transport(Scsi_Cmnd
        int need_auto_sense;
        int result;
 
+       /*
+        * Grab device's exclusive_access mutex to prevent libusb/usbfs from
+        * sending out a command in the middle of ours (if libusb sends a
+        * get_descriptor or something on pipe 0 after our CBW and before
+        * our CSW, and then we get a stall, we have trouble).
+        */
+       down(&(us->pusb_dev->exclusive_access));
+
        /* send the command to the transport layer */
        result = us->transport(srb, us);
+       up(&(us->pusb_dev->exclusive_access));
 
        /* if the command gets aborted by the higher layers, we need to
         * short-circuit all other processing
@@ -748,7 +757,9 @@ void usb_stor_invoke_transport(Scsi_Cmnd
                srb->use_sg = 0;
 
                /* issue the auto-sense command */
+               down(&(us->pusb_dev->exclusive_access));
                temp_result = us->transport(us->srb, us);
+               up(&(us->pusb_dev->exclusive_access));
 
                /* let's clean up right away */
                srb->request_buffer = old_request_buffer;
diff -urp -X dontdiff linux-2.4.28-pre1/drivers/usb/usb.c 
linux-2.4.28-pre1-usb/drivers/usb/usb.c
--- linux-2.4.28-pre1/drivers/usb/usb.c 2004-02-26 14:09:59.000000000 -0800
+++ linux-2.4.28-pre1-usb/drivers/usb/usb.c     2004-08-24 12:46:22.000000000 -0700
@@ -989,6 +989,7 @@ struct usb_device *usb_alloc_dev(struct 
        INIT_LIST_HEAD(&dev->filelist);
 
        init_MUTEX(&dev->serialize);
+       init_MUTEX(&dev->exclusive_access);
 
        dev->bus->op->allocate(dev);
 
diff -urp -X dontdiff linux-2.4.28-pre1/include/linux/usb.h 
linux-2.4.28-pre1-usb/include/linux/usb.h
--- linux-2.4.28-pre1/include/linux/usb.h       2004-08-24 15:42:51.000000000 -0700
+++ linux-2.4.28-pre1-usb/include/linux/usb.h   2004-08-24 20:56:55.000000000 -0700
@@ -828,6 +828,8 @@ struct usb_device {
 
        atomic_t refcnt;                /* Reference count */
        struct semaphore serialize;
+       struct semaphore exclusive_access; /* prevent driver & proc accesses  */
+                                          /* from overlapping cmds at device */
 
        unsigned int toggle[2];         /* one bit for each endpoint ([0] = IN, [1] = 
OUT) */
        unsigned int halted[2];         /* endpoint halts; one bit per endpoint # & 
direction; */


-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to