* Re: [PATCH usb-next] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT
[not found] <20261205031306.25065-1-xinsheng.zhu.ny@gmail.com>
@ 2026-12-05 3:25 ` sashiko-bot
0 siblings, 0 replies; only message in thread
From: sashiko-bot @ 2026-12-05 3:25 UTC (permalink / raw)
To: Xinsheng Zhu, linux-usb; +Cc: linux-rt-devel, linux-kernel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: gadget: pxa27x_udc: empty ep->lock pairs and unused
pflags in req_done()
--
commit 15927850a0e1e014c34b3d8d8f2da88f14a342f0
Author: Xinsheng Zhu <xinsheng.zhu.ny@gmail.com>
usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT
This commit replaces the explicit local_irq_save()/local_irq_restore()
calls around usb_gadget_giveback_request() in req_done() with
spin_unlock()/spin_lock() on ep->lock, acquiring and releasing ep->lock
with spin_lock_irqsave()/spin_unlock_irqrestore() when pflags is NULL.
> diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c
> index 9fd079cb65c6b..774e50d00d090 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);
> }
[Severity: Medium]
When pflags is NULL, should req_done() avoid taking and immediately
releasing ep->lock twice with no protected code in between?
On CONFIG_PREEMPT_RT, spin_lock_irqsave() does not change interrupt state
and only acquires a sleeping rt_spin_lock(). Callers passing NULL, such
as handle_ep0() and pxa_ep_dequeue(), now add two empty ep->lock cycles
that can contend with concurrent queue operations while protecting nothing.
Meanwhile, ep_del_request() earlier in req_done() remains outside this
lock acquisition; moving it before ep_del_request() (and keeping ep->lock
held in pxa_ep_dequeue()) would protect the queue update instead of
locking empty regions.
Also, *pflags is no longer dereferenced anywhere in req_done() or its
wrappers, so keeping unsigned long *pflags as a boolean while its
kernel-doc still describes it as saved spinlock flags is misleading.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205031306.25065-1-xinsheng.zhu.ny@gmail.com?part=1
^ permalink raw reply [flat|nested] only message in thread