All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Qianhui Xu" <xiaqinghuan@mail.ustc.edu.cn>
Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v9 3/3] usb: dwc3: select the shared HS data bus with a mux controller
Date: Tue, 17 Nov 2026 05:37:39 +0000	[thread overview]
Message-ID: <sashiko-outbox-218216@kernel.org> (raw)
In-Reply-To: <20261117052137.32833-4-xiaqinghuan@mail.ustc.edu.cn>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] usb: dwc3: unbalanced mux_control_deselect() in
  __dwc3_set_mode()
- [High] usb: dwc3: missing mux_control_deselect() on teardown in
  dwc3_drd_exit()
--

commit 39e198f2d73c2b8bec2fad2df66d23ccb21f5a72
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>

usb: dwc3: select the shared HS data bus with a mux controller

This commit adds support for switching a shared High Speed USB data bus
between two connectors using a mux controller and per-connector USB role
switches.

> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index fd5c2cd36c595..fe8e97d0398b1 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c

[ ... ]

> @@ -233,8 +246,47 @@ static void __dwc3_set_mode(struct work_struct *work)
>  		dwc3_writel(dwc, DWC3_GCTL, reg);
>  	}
>  
> +	/*
> +	 * The previous host or gadget instance has been torn down above, so the
> +	 * shared High Speed data path can now be moved to the requesting
> +	 * connector.  A failure here must not abort the mode change half-way:
> +	 * the controller would be left with a torn-down role and a stale
> +	 * current_dr_role, which the next request would tear down a second time.
> +	 */
> +	if (port_switch) {
> +		/*
> +		 * mux_control_select() sleeps while waiting for the controller, so
> +		 * the switch is only done here, in the mode worker.  The mux is kept
> +		 * selected between switches: dwc3 is its only consumer and always
> +		 * drives one of the two connectors.
> +		 */
> +		mux_control_deselect(mux->ctrl);
> +		ret = mux_control_select(mux->ctrl, mux_port);
> +		if (ret)
> +			dev_err_ratelimited(dwc->dev,
> +					    "failed to select USB port %d: %d\n",
> +					    mux_port, ret);
> +
> +		spin_lock_irqsave(&dwc->lock, flags);
> +		if (ret)
> +			mux->ports[mux_port].errors++;
> +		else
> +			mux->active_port = mux_port;
> +		spin_unlock_irqrestore(&dwc->lock, flags);
> +	}

[Severity: High]
Does calling mux_control_deselect(mux->ctrl) unconditionally here cause an
unbalanced deselect on the initial mode switch?

dwc3_role_mux_init() initializes mux->active_port to -1 without selecting
mux->ctrl.  When __dwc3_set_mode() runs for the initial mode request,
port_switch is true and mux_control_deselect() runs on an unselected mux,
driving idle_state without holding mux->ctrl->lock and calling up() on its
already-unlocked semaphore.

Also, if mux_control_select() fails after deselecting a previously active
port, mux->active_port keeps the old port index even though no port is
selected, so a subsequent switch either calls mux_control_deselect() again
on the deselected mux or skips mux_control_select() when switching back to
the old port.  Only call mux_control_deselect() when mux->active_port >= 0,
and reset mux->active_port to -1 when mux_control_select() fails.

> diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
> index f3e37d383627a..b6ca11e4c7b17 100644
> --- a/drivers/usb/dwc3/drd.c
> +++ b/drivers/usb/dwc3/drd.c

[ ... ]

> @@ -597,6 +888,7 @@ void dwc3_drd_exit(struct dwc3 *dwc)
>  {
>  	unsigned long flags;
>  
> +	dwc3_role_mux_exit(dwc);
>  	if (dwc->role_sw)
>  		usb_role_switch_unregister(dwc->role_sw);

[Severity: High]
Does dwc3_drd_exit() leave mux->ctrl selected when the driver is unbound or
removed?

__dwc3_set_mode() keeps mux->ctrl selected while a port is active, and
devm_mux_control_get() only calls mux_control_put() on release without
deselecting it.  After cancel_work_sync(&dwc->drd_work) and role teardown in
dwc3_drd_exit(), mux_control_deselect(mux->ctrl) is never called when
mux->active_port >= 0, leaving the mux idle state unrestored and
mux->ctrl->lock held so a later re-probe or mux consumer blocks in
mux_control_select().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117052137.32833-1-xiaqinghuan@mail.ustc.edu.cn?part=3

      reply	other threads:[~2026-11-17  5:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  5:21 [PATCH v9 0/3] usb: dwc3: support two connectors sharing one HS data bus Qianhui Xu
2026-11-17  5:21 ` [PATCH v9 1/3] dt-bindings: usb: snps,dwc3: two connectors are two endpoints of one port Qianhui Xu
2026-11-17  5:40   ` sashiko-bot
2026-11-17  5:21 ` [PATCH v9 2/3] usb: roles: look up role switches attached to a graph endpoint Qianhui Xu
2026-11-17  5:27   ` sashiko-bot
2026-11-17  5:21 ` [PATCH v9 3/3] usb: dwc3: select the shared HS data bus with a mux controller Qianhui Xu
2026-11-17  5:37   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-218216@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xiaqinghuan@mail.ustc.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.