usb: gadget: android: follow proper order on disconnect
authorDima Zavin <dima@android.com>
Wed, 14 Sep 2011 18:53:11 +0000 (11:53 -0700)
committerDima Zavin <dima@android.com>
Wed, 14 Sep 2011 20:43:19 +0000 (13:43 -0700)
We should composite_disconnect *before* updating our internal
state and sending uevent to userspace.
Also, hold cdev->lock while updating internal state.

Change-Id: If66a5a4f7d4a102a44aefc3ce4a154a5a1517dcf
Signed-off-by: Dima Zavin <dima@android.com>
drivers/usb/gadget/android.c

index b7e402921c65c777a28349ce9a888c0f1904f549..a7d5b19dc1614d7a5a893bc49df0f6bb58a2747c 100644 (file)
@@ -1081,9 +1081,15 @@ android_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *c)
 static void android_disconnect(struct usb_gadget *gadget)
 {
        struct android_dev *dev = _android_dev;
+       struct usb_composite_dev *cdev = get_gadget_data(gadget);
+       unsigned long flags;
+
+       composite_disconnect(gadget);
+
+       spin_lock_irqsave(&cdev->lock, flags);
        dev->connected = 0;
        schedule_work(&dev->work);
-       composite_disconnect(gadget);
+       spin_unlock_irqrestore(&cdev->lock, flags);
 }
 
 static int android_create_device(struct android_dev *dev)