On Sat, 3 Feb 2007, Oliver Neukum wrote:

> If you want simplicity, I'd suggest serialization. kmalloc for 4 bytes
> is overkill. I think it is even faster if we block on the cases there's
> a collision that go through kmalloc/kfree each time.

On the other hand, the same routine calls usb_control_message() which does 
two kmallocs: one for the URB and one for the usb_ctrlrequest structure.  
Adding a third for the buffer wouldn't be so bad.

Or we could pre-allocate everything; the ctrlrequest could even share the 
same cacheline as the I/O buffer.  But most hubs are idle almost all the 
time, and it doesn't seem worthwhile to allocate permanently one URB per 
hub if it will hardly ever be used.

Prakash, here's an alternative patch.  It should work just as well as the 
previous one (don't try to apply them both!).

Alan Stern


Index: usb-2.6/drivers/usb/core/hub.c
===================================================================
--- usb-2.6.orig/drivers/usb/core/hub.c
+++ usb-2.6/drivers/usb/core/hub.c
@@ -44,6 +44,7 @@ struct usb_hub {
                struct usb_hub_status   hub;
                struct usb_port_status  port;
        }                       *status;        /* buffer for status reports */
+       struct mutex            status_mutex;   /* for the status buffer */
 
        int                     error;          /* last reported error */
        int                     nerrors;        /* track consecutive errors */
@@ -545,6 +546,7 @@ static int hub_hub_status(struct usb_hub
 {
        int ret;
 
+       mutex_lock(&hub->status_mutex);
        ret = get_hub_status(hub->hdev, &hub->status->hub);
        if (ret < 0)
                dev_err (hub->intfdev,
@@ -554,6 +556,7 @@ static int hub_hub_status(struct usb_hub
                *change = le16_to_cpu(hub->status->hub.wHubChange); 
                ret = 0;
        }
+       mutex_unlock(&hub->status_mutex);
        return ret;
 }
 
@@ -627,6 +630,7 @@ static int hub_configure(struct usb_hub 
                ret = -ENOMEM;
                goto fail;
        }
+       mutex_init(&hub->status_mutex);
 
        hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL);
        if (!hub->descriptor) {
@@ -1423,6 +1427,7 @@ static int hub_port_status(struct usb_hu
 {
        int ret;
 
+       mutex_lock(&hub->status_mutex);
        ret = get_port_status(hub->hdev, port1, &hub->status->port);
        if (ret < 4) {
                dev_err (hub->intfdev,
@@ -1434,6 +1439,7 @@ static int hub_port_status(struct usb_hu
                *change = le16_to_cpu(hub->status->port.wPortChange); 
                ret = 0;
        }
+       mutex_unlock(&hub->status_mutex);
        return ret;
 }
 


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to