Linux USB
 help / color / mirror / Atom feed
* [PATCH usb-next] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT
@ 2026-12-05  3:13 Xinsheng Zhu
  2026-12-05  3:25 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Xinsheng Zhu @ 2026-12-05  3:13 UTC (permalink / raw)
  To: linux-usb
  Cc: nkapron, gregkh, daniel, haojian.zhuang, robert.jarzmik, bigeasy,
	clrkwllms, rostedt, linux-arm-kernel, linux-rt-devel

req_done() explicitly disables local interrupts around
usb_gadget_giveback_request(). The completion callback may acquire
spinlock_t locks, which become sleeping locks on PREEMPT_RT. Acquiring
such locks with interrupts disabled can result in a sleeping function
being called from an invalid context.

Follow the locking pattern introduced by commit 8d63c83d8eb9
("USB: gadget: dummy-hcd: Fix locking bug in RT-enabled kernels")
by using spin_unlock() and spin_lock() around the giveback. This
keeps interrupts disabled on non-RT kernels without explicitly
disabling them on PREEMPT_RT.

When pflags is NULL, establish the same interrupt state using
spin_lock_irqsave() and spin_unlock_irqrestore(). Otherwise,
reuse the caller's lock and saved interrupt state.

This preserves the original locking contract of req_done() and
leaves the endpoint queue locking unchanged.

Fixes: 5e23e90f3388 ("USB: pxa27x_udc: Fix deadlocks on request queueing")
Signed-off-by: Xinsheng Zhu <xinsheng.zhu.ny@gmail.com>
---
 drivers/usb/gadget/udc/pxa27x_udc.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c
index 9fd079cb65c6..774e50d00d09 100644
--- a/drivers/usb/gadget/udc/pxa27x_udc.c
+++ b/drivers/usb/gadget/udc/pxa27x_udc.c
@@ -672,13 +672,15 @@ static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status,
 			&req->req, status,
 			req->req.actual, req->req.length);
 
-	if (pflags)
-		spin_unlock_irqrestore(&ep->lock, *pflags);
-	local_irq_save(flags);
+	if (!pflags)
+		spin_lock_irqsave(&ep->lock, flags);
+
+	spin_unlock(&ep->lock);
 	usb_gadget_giveback_request(&req->udc_usb_ep->usb_ep, &req->req);
-	local_irq_restore(flags);
-	if (pflags)
-		spin_lock_irqsave(&ep->lock, *pflags);
+	spin_lock(&ep->lock);
+
+	if (!pflags)
+		spin_unlock_irqrestore(&ep->lock, flags);
 }
 
 /**

base-commit: 9357829ac604c28510b71b154cb6630af81226ff
-- 
2.54.0 (Apple Git-157)


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

end of thread, other threads:[~2026-12-05  3:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05  3:13 [PATCH usb-next] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT Xinsheng Zhu
2026-12-05  3:25 ` sashiko-bot

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