Linux USB
 help / color / mirror / Atom feed
* [PATCH 5.10.y-cip] usb: cdns3: gadget: fix state inconsistency on gadget init failure
@ 2026-11-27 12:18 Dickson Wu via B4 Relay
  2026-11-27 12:26 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Dickson Wu via B4 Relay @ 2026-11-27 12:18 UTC (permalink / raw)
  To: cip-dev
  Cc: Pavel Machek, Nobuhiro Iwamatsu, Ulrich Hecht, Yongchao Wu,
	linux-usb

From: Yongchao Wu <yongchao.wu@autochips.com>

commit c32f8748d70c8fc77676ad92ed76cede17bf2c48 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: 7733f6c32e36 ("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>
[ adapted to 5.10.y-cip: use gadget.c and cdns3_drd_gadget_off() ]
Signed-off-by: Dickson Wu <dickson.wu@certik.com>
---
5.10 has the old cdns3 layout, so the call goes in gadget.c and uses
cdns3_drd_gadget_off(). This failed to apply to 5.10.y and never made
it into a 5.10.y release, and 5.10.y is now end-of-life, so I'm sending
it here.

Tested on 5.10.275-cip80: the touched object
drivers/usb/cdns3/gadget.o builds with W=1. The same change on
v5.10.275 built with no new W=1 diagnostics and booted under QEMU. I
don't have Cadence hardware, so the failing-init path itself wasn't
exercised.

The backport and the test runs were prepared with AI coding tools
(OpenAI Codex agents, with review by Claude). I went over the result
before signing off.
---
 drivers/usb/cdns3/gadget.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c
index d0378ecd0c98..b6cb690208cd 100644
--- a/drivers/usb/cdns3/gadget.c
+++ b/drivers/usb/cdns3/gadget.c
@@ -3418,6 +3418,7 @@ static int __cdns3_gadget_init(struct cdns3 *cdns)
 	ret = cdns3_gadget_start(cdns);
 	if (ret) {
 		pm_runtime_put_sync(cdns->dev);
+		cdns3_drd_gadget_off(cdns);
 		return ret;
 	}
 

---
base-commit: bd8b111cdf1d9897bf4d826b7305a9c16bfe5f71
change-id: 20261127-cip-cdns3-510c-10094b795da1

Best regards,
--  
Dickson Wu <dickson.wu@certik.com>



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-27 12:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 12:18 [PATCH 5.10.y-cip] usb: cdns3: gadget: fix state inconsistency on gadget init failure Dickson Wu via B4 Relay
2026-11-27 12:26 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox