From: Jimmy Hu <hhhuuu@google.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org
Cc: Jimmy Hu <hhhuuu@google.com>, Kuen-Han Tsai <khtsai@google.com>,
Alan Stern <stern@rowland.harvard.edu>,
Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
Roy Luo <royluo@google.com>,
Robert Baldyga <r.baldyga@samsung.com>,
Felipe Balbi <balbi@ti.com>,
linux-kernel@vger.kernel.org, badhri@google.com
Subject: [PATCH] usb: gadget: udc: Fix permanent block caused by 'deactivated' flag
Date: Fri, 14 Nov 2025 16:08:41 +0800 [thread overview]
Message-ID: <20251114080841.829128-1-hhhuuu@google.com> (raw)
When setting a new USB configuration, some functions (e.g., UVC) can
call usb_function_deactivate() to set the `gadget->deactivated` flag
to `true`, intentionally blocking enumeration until a userspace
daemon (e.g., UVC service) is ready.
This `deactivated=true` state becomes a permanent block if this flag
is not cleared by usb_function_activate() (e.g., UVC service failure
or config set while unplugged). This blocked state persists even if
the cable is plugged/unplugged, as the vbus_event_work() handler is
still blocked by the `gadget->deactivated` flag, preventing pullup()
from being called.
This patch fixes this by modifying vbus_event_work() to clear the
`gadget->deactivated` flag *before* usb_udc_connect_control_locked().
This breaks the permanent block, so pullup() can now be called.
Fixes: ccdf138fe3e2 ("usb: gadget: add usb_gadget_activate/deactivate functions")
Signed-off-by: Jimmy Hu <hhhuuu@google.com>
---
drivers/usb/gadget/udc/core.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index 8dbe79bdc0f9..0195540d511a 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -1151,8 +1151,17 @@ static int usb_udc_connect_control_locked(struct usb_udc *udc) __must_hold(&udc-
static void vbus_event_work(struct work_struct *work)
{
struct usb_udc *udc = container_of(work, struct usb_udc, vbus_work);
+ struct usb_gadget *gadget = udc->gadget;
mutex_lock(&udc->connect_lock);
+
+ /*
+ * Clear the 'deactivated' flag on a VBUS event
+ * to break the blocked state.
+ */
+ if (gadget->deactivated)
+ gadget->deactivated = false;
+
usb_udc_connect_control_locked(udc);
mutex_unlock(&udc->connect_lock);
}
--
2.52.0.rc1.455.g30608eb744-goog
next reply other threads:[~2025-11-14 8:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 8:08 Jimmy Hu [this message]
2025-11-14 15:33 ` Alan Stern
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=20251114080841.829128-1-hhhuuu@google.com \
--to=hhhuuu@google.com \
--cc=Thinh.Nguyen@synopsys.com \
--cc=badhri@google.com \
--cc=balbi@ti.com \
--cc=gregkh@linuxfoundation.org \
--cc=khtsai@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=r.baldyga@samsung.com \
--cc=royluo@google.com \
--cc=stern@rowland.harvard.edu \
/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
all inboxes | Powered by JetHome®