All of lore.kernel.org
 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 v3] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT
Date: Sat, 05 Dec 2026 21:59:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-251931@kernel.org> (raw)
In-Reply-To: <20261205214738.93588-1-xinsheng.zhu.ny@gmail.com>

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

      reply	other threads:[~2026-12-05 21:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 21:47 [PATCH usb-next v3] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT Xinsheng Zhu
2026-12-05 21:59 ` 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-251931@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.