Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xinsheng Zhu" <xinsheng.zhu.ny@gmail.com>, linux-usb@vger.kernel.org
Cc: linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH usb-next] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT
Date: Sat, 05 Dec 2026 03:25:38 +0000	[thread overview]
Message-ID: <sashiko-outbox-250980@kernel.org> (raw)
In-Reply-To: <20261205031306.25065-1-xinsheng.zhu.ny@gmail.com>

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

      reply	other threads:[~2026-12-05  3:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 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-250980@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xinsheng.zhu.ny@gmail.com \
    /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