Somewhat surprisingly, the usbdev->children[] array isn't protected by any
sort of lock.  It's used in three ways: recording new devices as they are
detected by the upstream hub, removing devices during disconnect
processing, and error recovery in the hub driver.  Under normal conditions
all these activities occur in the khubd thread and so are serialized.  
But there are other conditions where disconnect processing occurs not in
khubd.  Thus we have the potential for races and errors.

Here's a list of the exceptional calls to usb_disconnect():

        HCD error handling (_really_ exceptional!):
                host/ohci-hcd.c:hc_restart()
                core/hcd.c:hcd_panic()

        Root hub removal (part of unregistering a USB bus):
                core/hcd-pci.c:usb_hcd_pci_remove()
                host/hc_sl811.c:hc_release_hci()
                host/ohci-sa1111.c:usb_hcd_sa1111_remove()

Clearly some sort of locking protection is needed.  The question is, what
sort?  The simplest approach is to add a semaphore or spinlock protecting
the children[] arrays.  But given that the exceptional accesses all occur
in situations that involve disconnecting all the devices on a bus, perhaps
there's a more clever way to do it (although I can't think of one
offhand).

Furthermore, there are problems the simple approach doesn't solve.  For
example, consider what happens when rmmod of an HCD is recursively
removing all the devices belong the root hub and is working its way
through the children[] array of some intermediate hub, removing the
entries one by one.  Suppose at the same time khubd detects a new device
plugged into that hub and so _fills in_ a blank children[] entry.  Not a
good scenario.

Any suggestions?

Alan Stern




-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&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