From: Ginger Li <ginger.jzllee@gmail.com>
To: vz@mleia.com, piotr.wojtaszczyk@timesys.com
Cc: linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] usb: gadget: lpc32xx_udc: Fix a race in lpc32xx_get_frame()
Date: Tue, 22 Sep 2026 14:53:57 +0800 [thread overview]
Message-ID: <20260922065357.18103-1-ginger.jzllee@gmail.com> (raw)
lpc32xx_get_frame() tests udc->clocked before it takes udc->lock, but
udc->clocked is cleared by udc_clk_set() with the lock held, for example from
lpc32xx_vbus_session() when the session is disconnected, which also gates the
UDC clock.
When the test passes on a stale value, udc_get_current_frame() then reads UDC
registers whose clock has already been turned off. Check udc->clocked inside
the critical section so that the state can not change between the check and
the register access.
Fixes: 24a28e428351 ("USB: gadget driver for LPC32xx")
Signed-off-by: Ginger Li <ginger.jzllee@gmail.com>
---
drivers/usb/gadget/udc/lpc32xx_udc.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/gadget/udc/lpc32xx_udc.c b/drivers/usb/gadget/udc/lpc32xx_udc.c
--- a/drivers/usb/gadget/udc/lpc32xx_udc.c
+++ b/drivers/usb/gadget/udc/lpc32xx_udc.c
@@ -2403,10 +2403,12 @@ static int lpc32xx_get_frame(struct usb_gadget *gadget
unsigned long flags;
struct lpc32xx_udc *udc = to_udc(gadget);
- if (!udc->clocked)
- return -EINVAL;
+ spin_lock_irqsave(&udc->lock, flags);
- spin_lock_irqsave(&udc->lock, flags);
+ if (!udc->clocked) {
+ spin_unlock_irqrestore(&udc->lock, flags);
+ return -EINVAL;
+ }
frame = (int) udc_get_current_frame(udc);
--
2.43.0
reply other threads:[~2026-09-22 6:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260922065357.18103-1-ginger.jzllee@gmail.com \
--to=ginger.jzllee@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=piotr.wojtaszczyk@timesys.com \
--cc=vz@mleia.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
all inboxes | Powered by JetHome®