Re: [PATCH] usb: gadget: fix race condition in UDC class

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

 



On Wed, 22 Sep 2010, Michal Nazarewicz wrote:

> This commit fixes a possible race condition in IDC class when
> usb_del_udc() is called concurrently to
> usb_gadget_register_driver() or usb_gadget_unregister_driver().
> 
> * NOT FOR MERGING, NOT TESTED, NOT EVEN COMPILED *

> After more thought I came up with a scheme where usage of atomic
> operations (xchg and cmpxchg) is enough to guarantee correctness.
> 
> The idea is that the driver field can have additional value:
> &udc_claimed.  This value means that usb_del_udc(),
> usb_gadget_register_driver() or usb_gadget_unregister_driver() does
> something with the UDC.  So basically, UDC can be in either of three
> states: free, busy or claimed where claimed means the above.
> 
> usb_gadget_register_driver() treats claimed UDCs as busy,
> usb_gadget_unregister_driver() as ones of no interest, and
> usb_del_udc() waits till the UDC is unclaimed.

Fancy coding schemes like this, in order to avoid proper locking, are 
incredibly difficult to do correctly.  It's just not worth it.  Don't 
try to be fancy; simply use a lock.

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