On Thu, 30 Jun 2011, Sarah Sharp wrote: > Hi Alan, > > In an upcoming patchset, I'm going to need to walk the USB tree in the > xHCI driver in order to gather some information during a device > configuration or alt setting change. Is there anything stopping the USB > tree from changing while this operation is in progress? Are you talking about a single bus or a whole bunch of buses? > I think I remember some USB device locks and some bus mutexes in the USB > core, but I think it would really be a layering violation if the xHCI > driver grabbed those. If you're doing a single bus then you don't have to lock the list of buses. But if you're iterating over multiple buses, you'll need to hold the usb_bus_list_lock mutex (defined in hcd.c) to prevent buses from being added or removed. (Although one wouldn't expect that mutex to be exported, oddly enough it is -- and the comment says it's for usbfs, which is part of usbcore anyway!) While iterating through a single bus, all you need to do is lock each device as you come to it (including the root hub), using usb_lock_device() and usb_unlock_device(). While you hold a device's lock, it can't be unregistered and it can't have any children added or removed. Don't worry too much about layering violations. usb_lock_device() is intended for use outside of usbcore. Using the usb_bus_list_lock _is_ a violation -- but that's kind of unavoidable, since walking the USB tree from within an HCD is already a layering violation on the face of it. > A bit of background: I'm going to need to walk the tree, starting from > the device under the roothub, "the device under the roothub"? Do you mean the root hub itself? Or do you mean the device_s_ under the root hub (i.e., the root hub's children)? > and capturing information about pretty > much all of its children. I may be able to cache some information about > the devices as their endpoints are added by the xHCI driver later as an > optimization. However, when I started down that path, I basically ended > up with a tree-like structure similar to what the USB core has. So I'd > rather re-use the USB core's tree in usb_device->children[] if I can. What information are you collecting and what do you want it for? Alan Stern -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html