linux/drivers/usb/cdns3
Yongchao Wu fb7110a052 usb: cdns3: gadget: fix state inconsistency on gadget init failure
commit c32f8748d7 upstream.

When cdns3_gadget_start() fails, the DRD hardware is left in gadget mode
while software state remains INACTIVE, creating hardware/software state
inconsistency.

When switching to host mode via sysfs:
  echo host > /sys/class/usb_role/13180000.usb-role-switch/role

The role state is not set to CDNS_ROLE_STATE_ACTIVE due to the error,
so cdns_role_stop() skips cleanup because state is still INACTIVE.
This violates the DRD controller design specification (Figure22),
which requires returning to idle state before switching roles.

This leads to a synchronous external abort in xhci_gen_setup() when
setting up the host controller:

[  516.440698] configfs-gadget 13180000.usb: failed to start g1: -19
[  516.442035] cdns-usb3 13180000.usb: Failed to add gadget
[  516.443278] cdns-usb3 13180000.usb: set role 2 has failed
...
[ 1301.375722] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
[ 1301.377716] Internal error: synchronous external abort: 96000010 [#1] PREEMPT SMP
[ 1301.382485] pc : xhci_gen_setup+0xa4/0x408
[ 1301.393391] backtrace:
    ...
    xhci_gen_setup+0xa4/0x408    <-- CRASH
    xhci_plat_setup+0x44/0x58
    usb_add_hcd+0x284/0x678
    ...
    cdns_role_set+0x9c/0xbc        <-- Role switch

Fix by calling cdns_drd_gadget_off() in the error path to properly
clean up the DRD gadget state.

Fixes: 7733f6c32e ("usb: cdns3: Add Cadence USB3 DRD Driver")
Cc: stable <stable@kernel.org>
Signed-off-by: Yongchao Wu <yongchao.wu@autochips.com>
Acked-by: Peter Chen <peter.chen@kernel.org>
Link: https://patch.msgid.link/20260401001000.5761-1-yongchao.wu@autochips.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-04-18 10:33:33 +02:00
..
cdns3-debug.h usb: cdns3: Change file names for cdns3 driver. 2020-12-29 12:36:13 +08:00
cdns3-ep0.c usb: cdns3: Fixed incorrect gadget state 2021-07-29 14:13:02 +08:00
cdns3-gadget.c usb: cdns3: gadget: fix state inconsistency on gadget init failure 2026-04-18 10:33:33 +02:00
cdns3-gadget.h usb: cdns3: fix iso transfer error when mult is not zero 2024-01-25 14:52:47 -08:00
cdns3-imx.c usb: cdns3: cdns3-imx: File headers are not good candidates for kernel-doc 2021-05-27 09:43:44 +02:00
cdns3-pci-wrap.c usb: cdns3: Fix double resource release in cdns3_pci_probe 2025-12-07 06:09:35 +09:00
cdns3-plat.c usb: cdns3: Put the cdns set active part outside the spin lock 2023-09-23 11:09:59 +02:00
cdns3-ti.c usb: cdns3: cdns3-ti: File headers are not good candidates for kernel-doc 2021-05-27 09:43:44 +02:00
cdns3-trace.c usb: cdns3: Change file names for cdns3 driver. 2020-12-29 12:36:13 +08:00
cdns3-trace.h usb: cdns3: trace: delete the trace parameter for request->trb 2021-04-12 20:19:21 +08:00
cdnsp-debug.h usb: cdnsp: Fix issue with CV Bad Descriptor test 2025-07-17 18:30:51 +02:00
cdnsp-ep0.c usb: cdnsp: Fix issue with CV Bad Descriptor test 2025-07-17 18:30:51 +02:00
cdnsp-gadget.c usb: cdns3: gadget: Use-after-free during failed initialization and exit of cdnsp gadget 2025-12-07 06:09:21 +09:00
cdnsp-gadget.h usb: cdnsp: Fix issue with CV Bad Descriptor test 2025-07-17 18:30:51 +02:00
cdnsp-mem.c usb: cdnsp: Fix a NULL pointer dereference in cdnsp_endpoint_init() 2021-12-08 09:04:56 +01:00
cdnsp-pci.c usb: cdns3: cdnsp-pci: remove redundant pci_disable_device() call 2025-10-19 16:21:39 +02:00
cdnsp-ring.c usb: cdnsp: Fix issue with CV Bad Descriptor test 2025-07-17 18:30:51 +02:00
cdnsp-trace.c usb: cdnsp: Add tracepoints for CDNSP driver 2020-12-29 12:36:13 +08:00
cdnsp-trace.h usb: cdnsp: Fix issue in cdnsp_log_ep trace event 2021-12-22 09:32:46 +01:00
core.c usb: cdns3: fix role switching during resume 2026-04-18 10:33:07 +02:00
core.h usb: cdnsp: Fix issue with resuming from L1 2025-05-18 08:20:37 +02:00
drd.c usb: cdns3: Add quirk flag to enable suspend residency 2025-01-09 13:28:29 +01:00
drd.h usb: cdns3: Add quirk flag to enable suspend residency 2025-01-09 13:28:29 +01:00
gadget-export.h usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver 2020-12-29 12:36:13 +08:00
host-export.h usb: cdns3: Removes xhci_cdns3_suspend_quirk from host-export.h 2020-12-29 12:36:13 +08:00
host.c usb: xhci: fix loss of data on Cadence xHC 2024-10-17 15:11:17 +02:00
Kconfig usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver 2020-12-29 12:36:13 +08:00
Makefile usb: cdnsp: fixes undefined reference to cdns_remove 2021-01-14 09:02:00 +08:00