Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fang Xieyan" <fangxy@xiaopeng.com>, linux-usb@vger.kernel.org
Subject: Re: [PATCH v2] usb: gadget: lpc32xx_udc: handle interrupts with an empty queue
Date: Sat, 21 Nov 2026 15:20:28 +0000	[thread overview]
Message-ID: <sashiko-outbox-227118@kernel.org> (raw)
In-Reply-To: <20261121151233.82306-1-fangxy@xiaopeng.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] usb: gadget: lpc32xx_udc: incomplete dequeue fix corrupts
  active requests
--

commit 48ddd0ae77fc12c24e8e346c29dd18e939ebec47
Author: Fang Xieyan <fangxy@xiaopeng.com>

usb: gadget: lpc32xx_udc: handle interrupts with an empty queue

This commit checks whether ep->queue is empty in udc_handle_eps() and
udc_handle_dma_ep() before accessing the head request, disabling the
endpoint interrupt or DMA channel and clearing pending DMA interrupts when
no request is queued.

> diff --git a/drivers/usb/gadget/udc/lpc32xx_udc.c b/drivers/usb/gadget/udc/lpc32xx_udc.c
> index 94355d3d930fd..8d6b9f356589c 100644
> --- a/drivers/usb/gadget/udc/lpc32xx_udc.c
> +++ b/drivers/usb/gadget/udc/lpc32xx_udc.c
> @@ -1945,6 +1945,13 @@ static void udc_handle_eps(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep)
>  	/* Get endpoint status */
>  	epstatus = udc_clearep_getsts(udc, ep->hwep_num);
>  
> +	/* The request may have been dequeued; nothing is left to complete. */
> +	if (list_empty(&ep->queue)) {
> +		ep->req_pending = 0;
> +		uda_disable_hwepint(udc, ep->hwep_num);
> +		return;
> +	}
> +
>  	/*
>  	 * This should never happen, but protect against writing to the
>  	 * buffer when full.
> @@ -1958,7 +1965,6 @@ static void udc_handle_eps(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep)
>  	} else
>  		return;
>  
> -	/* If there isn't a request waiting, something went wrong */
>  	req = list_entry(ep->queue.next, struct lpc32xx_request, queue);
>  
>  	done(ep, req, 0);
> @@ -1985,6 +1991,23 @@ static void udc_handle_dma_ep(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep)
>  	ep->totalints++;
>  #endif
>  
> +	/* The request may have been dequeued; still clear the pending interrupts. */
> +	if (list_empty(&ep->queue)) {
> +		u32 mask = 1U << ep->hwep_num;
> +
> +		ep->req_pending = 0;
> +
> +		/* Disable DMA and clear pending interrupts */
> +		udc_ep_dma_disable(udc, ep->hwep_num);
> +		writel(mask, USBD_EOTINTCLR(udc->udp_baseaddr));
> +		writel(mask, USBD_NDDRTINTCLR(udc->udp_baseaddr));
> +
> +		if (readl(USBD_SYSERRTINTST(udc->udp_baseaddr)) & mask)
> +			writel(mask, USBD_SYSERRTINTCLR(udc->udp_baseaddr));
> +
> +		return;
> +	}
> +
>  	req = list_entry(ep->queue.next, struct lpc32xx_request, queue);
>  	dd = req->dd_desc_ptr;

[Severity: High]
What happens if ep->queue is not empty when the pending interrupt from the
dequeued request fires—for example, because a second request was already
queued behind it, or the completion callback queued a new request while
done() dropped udc->lock for usb_gadget_giveback_request()?

Because lpc32xx_ep_dequeue() simply calls done(ep, req, -ECONNRESET)
without stopping DMA or clearing the endpoint and DMA interrupts before
unmapping the buffer and freeing req->dd_desc_ptr, list_empty(&ep->queue)
will be false and the stale interrupt from the dequeued request will be
attributed to the new head request: udc_handle_eps() will send the
dequeued request's deferred ZLP and prematurely complete the new request,
while udc_handle_dma_ep() will see an unretired dd_desc_ptr on the new
request and abort it with -ECONNABORTED.

Dequeueing an in-flight head request in lpc32xx_ep_dequeue() before DMA
completes also unmaps its buffer and frees req->dd_desc_ptr while DMA is
still active on udc->udca_v_base[ep->hwep_num], and leaves any remaining
requests in ep->queue stalled with ep->req_pending = 0.  Should
lpc32xx_ep_dequeue() disable DMA, clear the pending interrupts and start
the next request when removing the head of ep->queue?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261121151233.82306-1-fangxy@xiaopeng.com?part=1

      reply	other threads:[~2026-11-21 15:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 15:12 [PATCH v2] usb: gadget: lpc32xx_udc: handle interrupts with an empty queue Fang Xieyan
2026-11-21 15:20 ` 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-227118@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=fangxy@xiaopeng.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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