Skip to content

Commit 99b2425

Browse files
Fabrice Gasniergregkh
authored andcommitted
usb: dwc2: drd: fix soft connect when gadget is unconfigured
commit 32fde84 upstream. When the gadget driver hasn't been (yet) configured, and the cable is connected to a HOST, the SFTDISCON gets cleared unconditionally, so the HOST tries to enumerate it. At the host side, this can result in a stuck USB port or worse. When getting lucky, some dmesg can be observed at the host side: new high-speed USB device number ... device descriptor read/64, error -110 Fix it in drd, by checking the enabled flag before calling dwc2_hsotg_core_connect(). It will be called later, once configured, by the normal flow: - udc_bind_to_driver - usb_gadget_connect - dwc2_hsotg_pullup - dwc2_hsotg_core_connect Fixes: 17f9340 ("usb: dwc2: override PHY input signals with usb role switch support") Cc: stable <stable@vger.kernel.org> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> Link: https://lore.kernel.org/r/1644999135-13478-1-git-send-email-fabrice.gasnier@foss.st.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c786688 commit 99b2425

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

drivers/usb/dwc2/core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,7 @@ void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg);
14061406
void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2);
14071407
int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
14081408
#define dwc2_is_device_connected(hsotg) (hsotg->connected)
1409+
#define dwc2_is_device_enabled(hsotg) (hsotg->enabled)
14091410
int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg);
14101411
int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg, int remote_wakeup);
14111412
int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg);
@@ -1434,6 +1435,7 @@ static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
14341435
int testmode)
14351436
{ return 0; }
14361437
#define dwc2_is_device_connected(hsotg) (0)
1438+
#define dwc2_is_device_enabled(hsotg) (0)
14371439
static inline int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
14381440
{ return 0; }
14391441
static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg,

drivers/usb/dwc2/drd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ static int dwc2_drd_role_sw_set(struct usb_role_switch *sw, enum usb_role role)
109109
already = dwc2_ovr_avalid(hsotg, true);
110110
} else if (role == USB_ROLE_DEVICE) {
111111
already = dwc2_ovr_bvalid(hsotg, true);
112-
/* This clear DCTL.SFTDISCON bit */
113-
dwc2_hsotg_core_connect(hsotg);
112+
if (dwc2_is_device_enabled(hsotg)) {
113+
/* This clear DCTL.SFTDISCON bit */
114+
dwc2_hsotg_core_connect(hsotg);
115+
}
114116
} else {
115117
if (dwc2_is_device_mode(hsotg)) {
116118
if (!dwc2_ovr_bvalid(hsotg, false))

0 commit comments

Comments
 (0)