USB: dummy-hcd: Fix erroneous synchronization change
authorAlan Stern <stern@rowland.harvard.edu>
Tue, 26 Sep 2017 19:15:49 +0000 (15:15 -0400)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Thu, 28 Sep 2017 09:30:59 +0000 (12:30 +0300)
commit7dbd8f4cabd96db5a50513de9d83a8105a5ffc81
treeb65264c4c74ff8477910fae3cb8f1afa1bb4e1c1
parent0173a68bfb0ad1c72a6ee39cc485aa2c97540b98
USB: dummy-hcd: Fix erroneous synchronization change

A recent change to the synchronization in dummy-hcd was incorrect.
The issue was that dummy_udc_stop() contained no locking and therefore
could race with various gadget driver callbacks, and the fix was to
add locking and issue the callbacks with the private spinlock held.

UDC drivers aren't supposed to do this.  Gadget driver callback
routines are allowed to invoke functions in the UDC driver, and these
functions will generally try to acquire the private spinlock.  This
would deadlock the driver.

The correct solution is to drop the spinlock before issuing callbacks,
and avoid races by emulating the synchronize_irq() call that all real
UDC drivers must perform in their ->udc_stop() routines after
disabling interrupts.  This involves adding a flag to dummy-hcd's
private structure to keep track of whether interrupts are supposed to
be enabled, and adding a counter to keep track of ongoing callbacks so
that dummy_udc_stop() can wait for them all to finish.

A real UDC driver won't receive disconnect, reset, suspend, resume, or
setup events once it has disabled interrupts.  dummy-hcd will receive
them but won't try to issue any gadget driver callbacks, which should
be just as good.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Fixes: f16443a034c7 ("USB: gadgetfs, dummy-hcd, net2280: fix locking for callbacks")
CC: <stable@vger.kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
drivers/usb/gadget/udc/dummy_hcd.c