usb: gadget: composite: Fix cdev null after rmmod
Peter Chiang [Fri, 25 Sep 2015 10:04:17 +0000 (18:04 +0800)]
Avoid to disconnect gadget again after unbinding

bug 200141741

Change-Id: I6fadcb4c5b5262d861a865f24ba2d8666e126923
Signed-off-by: Peter Chiang <pchiang@nvidia.com>
Reviewed-on: http://git-master/r/805175
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Bibek Basu <bbasu@nvidia.com>
Reviewed-by: Hui Fu <hfu@nvidia.com>
Reviewed-by: Ashutosh Jha <ajha@nvidia.com>

drivers/usb/gadget/composite.c

index 024bba4..e830783 100644 (file)
@@ -2,7 +2,7 @@
  * composite.c - infrastructure for Composite USB Gadgets
  *
  * Copyright (C) 2006-2008 David Brownell
- * Copyright (c) 2013 NVIDIA CORPORATION. All rights reserved.
+ * Copyright (c) 2015 NVIDIA CORPORATION. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -1520,6 +1520,9 @@ void composite_disconnect(struct usb_gadget *gadget)
        /* REVISIT:  should we have config and device level
         * disconnect callbacks?
         */
+       if (!cdev)
+               return;
+
        spin_lock_irqsave(&cdev->lock, flags);
        if (cdev->config)
                reset_config(cdev);