Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ilia Snezhkov" <iasnezhkov@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: roles: serialize registered checks and unregister under sw->lock
Date: Wed, 25 Nov 2026 23:55:28 +0000	[thread overview]
Message-ID: <sashiko-outbox-234419@kernel.org> (raw)
In-Reply-To: <20261125234825.94733-1-iasnezhkov@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] usb: roles: ABBA deadlock between usb_role_switch_unregister()
  and dwc3-apple
--

commit e0b16766d03a43b431963aa2b14fba31f31089de
Author: Ilia Snezhkov <iasnezhkov@gmail.com>

usb: roles: serialize registered checks and unregister under sw->lock

This commit moves the sw->registered check inside sw->lock in
usb_role_switch_set_role() and usb_role_switch_get_role(), and acquires
sw->lock when clearing sw->registered in usb_role_switch_unregister().

> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index 8ea703e63ffbd..0a13c871c71f2 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
[ ... ]
> @@ -423,7 +428,9 @@ void usb_role_switch_unregister(struct usb_role_switch *sw)
>  {
>  	if (IS_ERR_OR_NULL(sw))
>  		return;
> +	mutex_lock(&sw->lock);
>  	sw->registered = false;
> +	mutex_unlock(&sw->lock);
>  	if (dev_fwnode(&sw->dev))
>  		component_del(&sw->dev, &connector_ops);
>  	device_unregister(&sw->dev);

[Severity: High]
Can taking sw->lock in usb_role_switch_unregister() cause an ABBA deadlock
with appledwc->lock in dwc3-apple?

usb_role_switch_set_role() and usb_role_switch_get_role() invoke sw->set()
and sw->get() under sw->lock, and the dwc3-apple callbacks acquire
appledwc->lock.  Conversely, dwc3_apple_remove() calls
usb_role_switch_unregister() while already holding appledwc->lock:

drivers/usb/dwc3/dwc3-apple.c:dwc3_apple_remove() {
	...
	guard(mutex)(&appledwc->lock);

	usb_role_switch_unregister(appledwc->role_sw);
	...
}

CPU0                              CPU1
----                              ----
lock(&appledwc->lock)
                                  lock(&sw->lock)
lock(&sw->lock)
                                  lock(&appledwc->lock)

 *** DEADLOCK ***

CPU0: dwc3_apple_remove() -> usb_role_switch_unregister()
CPU1: usb_role_switch_set_role() -> dwc3_usb_role_switch_set()

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125234825.94733-1-iasnezhkov@gmail.com?part=1

      reply	other threads:[~2026-11-25 23:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 23:48 [PATCH] usb: roles: serialize registered checks and unregister under sw->lock Ilia Snezhkov via B4 Relay
2026-11-25 23:55 ` 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-234419@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=iasnezhkov@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox