* Re: [PATCH usb-next v3] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT
[not found] <20261205214738.93588-1-xinsheng.zhu.ny@gmail.com>
@ 2026-12-05 21:59 ` sashiko-bot
0 siblings, 0 replies; only message in thread
From: sashiko-bot @ 2026-12-05 21:59 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:
- [Low] usb: gadget: pxa27x_udc: conditional locked flag in req_done()
and helpers
--
commit b1b33eb4417e50b1d8e93191abd1644e0e2f2fb3
Author: Xinsheng Zhu <xinsheng.zhu.ny@gmail.com>
usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT
This commit replaces local_irq_save()/local_irq_restore() around
usb_gadget_giveback_request() in req_done() with spin_unlock()/spin_lock(),
keeps ep->lock held across request lookup and removal in pxa_ep_dequeue(),
and replaces pflags with a boolean locked flag across req_done() and its
completion helpers.
> diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c
> index 9fd079cb65c6b..219833e681657 100644
> --- a/drivers/usb/gadget/udc/pxa27x_udc.c
> +++ b/drivers/usb/gadget/udc/pxa27x_udc.c
[ ... ]
> static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status,
> - unsigned long *pflags)
> + bool locked)
> {
> unsigned long flags;
>
> + if (!locked)
> + spin_lock_irqsave(&ep->lock, flags);
> +
> ep_del_request(ep, req);
> if (likely(req->req.status == -EINPROGRESS))
> req->req.status = status;
> @@ -672,37 +677,36 @@ 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);
> + 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 (!locked)
> + spin_unlock_irqrestore(&ep->lock, flags);
> }
>
> /**
> * ep_end_out_req - Ends endpoint OUT request
> * @ep: physical endpoint
> * @req: pxa request
> - * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held
> + * @locked: whether the caller holds ep->lock with spin_lock_irqsave()
> *
> * Context: ep->lock held or released (see req_done())
> *
> * Ends endpoint OUT request (completes usb request).
> */
> static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req,
> - unsigned long *pflags)
> + bool locked)
> {
> inc_ep_stats_reqs(ep, !USB_DIR_IN);
> - req_done(ep, req, 0, pflags);
> + req_done(ep, req, 0, locked);
> }
[Severity: Low]
Could req_done(), ep_end_in_req(), and ep_end_out_req() require ep->lock
to be held unconditionally instead of threading bool locked through five
helpers?
Conditionally acquiring and releasing ep->lock in req_done() produces
sparse context-imbalance warnings and prevents asserting the lock with
lockdep_assert_held(). When locked is false, ep_end_in_req() and
ep_end_out_req() also update ep->stats via inc_ep_stats_reqs() before
req_done() acquires ep->lock.
Both ep0_end_in_req() and ep0_end_out_req() are only ever called with
locked set to false. Acquiring ep->lock in those two helpers and around
the WAIT_ACK_SET_CONF_INTERF call to ep_end_in_req() in pxa_ep_queue()
would drop the locked parameter, keep sparse happy, and protect ep->stats.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205214738.93588-1-xinsheng.zhu.ny@gmail.com?part=1
^ permalink raw reply [flat|nested] only message in thread