From: Milan Svoboda Date: Mon, 26 Jun 2006 14:46:00 +0000 (-0700) Subject: USB: correct locking in gadgetfs_disconnect X-Git-Tag: v2.6.19-rc1~899^2~81 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07cb7f23d07aa4d197dbeb123eb9719c176190ee;p=linux-2.6 USB: correct locking in gadgetfs_disconnect This patch moves spin_lock (&dev->lock) before first use of dev. I think that test to the state of device should be protected with this spin_lock... Signed-off-by: Milan Svoboda Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c index 2a7162d897..da85732fa9 100644 --- a/drivers/usb/gadget/inode.c +++ b/drivers/usb/gadget/inode.c @@ -1696,16 +1696,17 @@ gadgetfs_disconnect (struct usb_gadget *gadget) { struct dev_data *dev = get_gadget_data (gadget); + spin_lock (&dev->lock); if (dev->state == STATE_UNCONNECTED) { DBG (dev, "already unconnected\n"); - return; + goto exit; } dev->state = STATE_UNCONNECTED; INFO (dev, "disconnected\n"); - spin_lock (&dev->lock); next_event (dev, GADGETFS_DISCONNECT); ep0_readable (dev); +exit: spin_unlock (&dev->lock); }