I don't know what others think, but I think you missed a spot.  devrequets
is also used in the storage/ directory.

Matt

On Wed, Dec 12, 2001 at 12:30:44AM +0100, Oliver Neukum wrote:
> Hi,
> 
> here's the patch that introduces a buffer for usb_control_msg
> and fixes memory allocations in danger of deadlocking in usb.c
> 
> What do you think ?
> 
>       Regards
>               Oliver
> 
> 
> --- include/linux/usb.h.alt   Sun Dec  9 13:49:56 2001
> +++ include/linux/usb.h       Wed Dec 12 00:19:26 2001
> @@ -617,6 +617,9 @@
>                                       /* [0] = IN, [1] = OUT */
>       int epmaxpacketin[16];          /* INput endpoint specific maximums */
>       int epmaxpacketout[16];         /* OUTput endpoint specific maximums */
> +
> +     devrequest dr;                  /* scratch buffer for control messages */
> +     struct semaphore dr_lock;       /* lock for it */
>  
>       struct usb_device *parent;
>       struct usb_bus *bus;            /* Bus we're part of */
> --- drivers/usb/usb.c.alt     Thu Dec  6 22:12:55 2001
> +++ drivers/usb/usb.c Wed Dec 12 00:22:54 2001
> @@ -946,6 +946,7 @@
>       INIT_LIST_HEAD(&dev->filelist);
>  
>       init_MUTEX(&dev->serialize);
> +     init_MUTEX(&dev->dr_lock);
>  
>       dev->bus->op->allocate(dev);
>  
> @@ -990,7 +991,7 @@
>       urb_t *urb;
>  
>       urb = (urb_t *)kmalloc(sizeof(urb_t) + iso_packets * 
>sizeof(iso_packet_descriptor_t),
> -           in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
> +           GFP_ATOMIC );
>       if (!urb) {
>               err("alloc_urb: kmalloc failed");
>               return NULL;
> @@ -1154,23 +1155,20 @@
>  int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u8 
>requesttype,
>                        __u16 value, __u16 index, void *data, __u16 size, int timeout)
>  {
> -     devrequest *dr = kmalloc(sizeof(devrequest), GFP_KERNEL);
>       int ret;
> -     
> -     if (!dr)
> -             return -ENOMEM;
> +     devrequest *dr = &dev->dr;
>  
> +     down(&dev->dr_lock);
>       dr->requesttype = requesttype;
>       dr->request = request;
>       dr->value = cpu_to_le16p(&value);
>       dr->index = cpu_to_le16p(&index);
>       dr->length = cpu_to_le16p(&size);
>  
> -     //dbg("usb_control_msg");       
> +     //dbg("usb_control_msg");
>  
>       ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout);
> -
> -     kfree(dr);
> +     up(&dev->dr_lock);
>  
>       return ret;
>  }
> @@ -1913,7 +1911,7 @@
>       if (result < 0)
>               return result;
>  
> -     buffer = kmalloc(sizeof(status), GFP_KERNEL);
> +     buffer = kmalloc(sizeof(status), GFP_NOIO); /* possible use by usb-storage */
>       if (!buffer) {
>               err("unable to allocate memory for configuration descriptors");
>               return -ENOMEM;
> 
> _______________________________________________
> [EMAIL PROTECTED]
> To unsubscribe, use the last form field at:
> https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

-- 
Matthew Dharm                              Home: [EMAIL PROTECTED] 
Maintainer, Linux USB Mass Storage Driver

SP: I sell software for Microsoft.  Can you set me free?
DP: Natural Selection says I shouldn't.
                                        -- MS Salesman and Dust Puppy
User Friendly, 4/2/1998

Attachment: msg03281/pgp00000.pgp
Description: PGP signature

Reply via email to