Skip to content

Commit 207324a

Browse files
Minas Harutyunyangregkh
authored andcommitted
usb: dwc2: Postponed gadget registration to the udc class driver
During dwc2 driver probe, after gadget registration to the udc class driver, if exist any builtin function driver it immediately bound to dwc2 and after init host side (dwc2_hcd_init()) stucked in host mode. Patch postpone gadget registration after host side initialization done. Fixes: 117777b ("usb: dwc2: Move gadget probe function into platform code") Reported-by: kbuild test robot <[email protected]> Tested-by: Marek Vasut <[email protected]> Cc: stable <[email protected]> Signed-off-by: Minas Harutyunyan <[email protected]> Link: https://lore.kernel.org/r/f21cb38fecc72a230b86155d94c7e60c9cb66f58.1591690938.git.hminas@synopsys.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5d80219 commit 207324a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

drivers/usb/dwc2/gadget.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4920,12 +4920,6 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
49204920
epnum, 0);
49214921
}
49224922

4923-
ret = usb_add_gadget_udc(dev, &hsotg->gadget);
4924-
if (ret) {
4925-
dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep,
4926-
hsotg->ctrl_req);
4927-
return ret;
4928-
}
49294923
dwc2_hsotg_dump(hsotg);
49304924

49314925
return 0;

drivers/usb/dwc2/platform.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,17 @@ static int dwc2_driver_probe(struct platform_device *dev)
575575
if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)
576576
dwc2_lowlevel_hw_disable(hsotg);
577577

578+
#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
579+
IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
580+
/* Postponed adding a new gadget to the udc class driver list */
581+
if (hsotg->gadget_enabled) {
582+
retval = usb_add_gadget_udc(hsotg->dev, &hsotg->gadget);
583+
if (retval) {
584+
dwc2_hsotg_remove(hsotg);
585+
goto error_init;
586+
}
587+
}
588+
#endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
578589
return 0;
579590

580591
error_init:

0 commit comments

Comments
 (0)