Re: Walking the USB tree?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 30 Jun 2011, Sarah Sharp wrote:

> On Thu, Jun 30, 2011 at 05:01:36PM -0400, Alan Stern wrote:
> > 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.
> 
> Say I have this tree:
> 
> 		port 2
> 		  |
> 		HS hub 1
> 		/	\
> 	HS hub 2	HS device 3
> 
> If I call usb_lock_device() for HS device 3, and then for HS hub 1,
> does that prevent children from being added or removed from HS hub 2?

Ack!  Don't do that!  The device-model locking rules require that locks
be acquired going _down_ the tree, never _up_.  Therefore you must
never call usb_lock_device() for hub 1 while holding the lock for
either hub 2 or device 3.

To answer your question: The only way to prevent children from being
added to hub 2 is to lock hub 2.  You can prevent a child from being 
removed from hub 2 by locking hub 2, the child, or any of the child's 
descendants.

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


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux