Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755264AbeAIHBD (ORCPT + 1 other); Tue, 9 Jan 2018 02:01:03 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:45693 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753073AbeAIHBA (ORCPT ); Tue, 9 Jan 2018 02:01:00 -0500 X-Google-Smtp-Source: ACJfBoudjRUrCggql4y5hbIXP4V+otnRownyr2tarCxqDfEMUmE+eO68pbX4FbP4kgYAinAwrztayw== From: Amit Pundir To: lkml , linux-usb@vger.kernel.org Cc: Hemant Kumar , Felipe Balbi , Greg KH , Michal Nazarewicz , John Stultz , Dmitry Shmidt , Badhri , Android Kernel Team , stable@vger.kernel.org Subject: [PATCH] usb: f_fs: Prevent gadget unbind if it is already unbound Date: Tue, 9 Jan 2018 12:30:53 +0530 Message-Id: <1515481253-10415-1-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: From: Hemant Kumar Upon usb composition switch there is possibility of ep0 file release happening after gadget driver bind. In case of composition switch from adb to a non-adb composition gadget will never gets bound again resulting into failure of usb device enumeration. Fix this issue by checking FFS_FL_BOUND flag and avoid extra gadget driver unbind if it is already done as part of composition switch. This fixes adb reconnection error reported on Android running v4.4 and above kernel versions. Verified on Hikey running vanilla v4.15-rc7 + few out of tree Mali patches. Reviewed-at: https://android-review.googlesource.com/#/c/582632/ Cc: Felipe Balbi Cc: Greg KH Cc: Michal Nazarewicz Cc: John Stultz Cc: Dmitry Shmidt Cc: Badhri Cc: Android Kernel Team Cc: stable@vger.kernel.org Signed-off-by: Hemant Kumar [AmitP: Cherry-picked it from android-4.14 and updated the commit log] Signed-off-by: Amit Pundir --- drivers/usb/gadget/function/f_fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index b6cf5ab5a0a1..f9bd351637cd 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -3700,7 +3700,8 @@ static void ffs_closed(struct ffs_data *ffs) ci = opts->func_inst.group.cg_item.ci_parent->ci_parent; ffs_dev_unlock(); - unregister_gadget_item(ci); + if (test_bit(FFS_FL_BOUND, &ffs->flags)) + unregister_gadget_item(ci); return; done: ffs_dev_unlock(); -- 2.7.4