* [PATCH 1/2] usb: gadget: m66592-udc: recheck ep->queue after reacquiring lock
@ 2026-11-30 10:34 Ziheng Wei
2026-11-30 10:34 ` [PATCH 2/2] usb: gadget: r8a66597-udc: " Ziheng Wei
0 siblings, 1 reply; 2+ messages in thread
From: Ziheng Wei @ 2026-11-30 10:34 UTC (permalink / raw)
To: Neill Kapron, Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel
In transfer_complete(), restart is computed from !list_empty(&ep->queue)
before dropping ep->m66592->lock for usb_gadget_giveback_request(). While
unlocked, the completion callback or a concurrent m66592_dequeue() can
empty ep->queue while ep->ep.desc remains set, causing list_entry() to
pass a bogus pointer to start_packet() once the lock is reacquired.
Recheck !list_empty(&ep->queue) after reacquiring ep->m66592->lock.
Found by LLM-assisted static analysis and runtime-tested in QEMU+KASAN
(null-ptr-deref Oops in start_packet() before the fix; 0 findings after).
Signed-off-by: Ziheng Wei <zihengw03@163.com>
---
drivers/usb/gadget/udc/m66592-udc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/udc/m66592-udc.c b/drivers/usb/gadget/udc/m66592-udc.c
index d77c11c4e..97cca8442 100644
--- a/drivers/usb/gadget/udc/m66592-udc.c
+++ b/drivers/usb/gadget/udc/m66592-udc.c
@@ -729,7 +729,7 @@ __acquires(m66592->lock)
usb_gadget_giveback_request(&ep->ep, &req->req);
spin_lock(&ep->m66592->lock);
- if (restart) {
+ if (restart && !list_empty(&ep->queue)) {
req = list_entry(ep->queue.next, struct m66592_request, queue);
if (ep->ep.desc)
start_packet(ep, req);
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread* [PATCH 2/2] usb: gadget: r8a66597-udc: recheck ep->queue after reacquiring lock
2026-11-30 10:34 [PATCH 1/2] usb: gadget: m66592-udc: recheck ep->queue after reacquiring lock Ziheng Wei
@ 2026-11-30 10:34 ` Ziheng Wei
0 siblings, 0 replies; 2+ messages in thread
From: Ziheng Wei @ 2026-11-30 10:34 UTC (permalink / raw)
To: Neill Kapron, Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel
In transfer_complete(), restart is computed from !list_empty(&ep->queue)
before dropping ep->r8a66597->lock for usb_gadget_giveback_request().
While unlocked, the completion callback or a concurrent r8a66597_dequeue()
can empty ep->queue while ep->ep.desc remains set, causing
get_request_from_ep() to pass a bogus pointer to start_packet().
Recheck !list_empty(&ep->queue) after reacquiring ep->r8a66597->lock.
Found by LLM-assisted static analysis and runtime-tested in QEMU+KASAN
(null-ptr-deref Oops in start_packet() before the fix; 0 findings after).
Signed-off-by: Ziheng Wei <zihengw03@163.com>
---
drivers/usb/gadget/udc/r8a66597-udc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/udc/r8a66597-udc.c b/drivers/usb/gadget/udc/r8a66597-udc.c
index 469075b06..9e65a5dd9 100644
--- a/drivers/usb/gadget/udc/r8a66597-udc.c
+++ b/drivers/usb/gadget/udc/r8a66597-udc.c
@@ -925,7 +925,7 @@ __acquires(r8a66597->lock)
usb_gadget_giveback_request(&ep->ep, &req->req);
spin_lock(&ep->r8a66597->lock);
- if (restart) {
+ if (restart && !list_empty(&ep->queue)) {
req = get_request_from_ep(ep);
if (ep->ep.desc)
start_packet(ep, req);
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 10:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 10:34 [PATCH 1/2] usb: gadget: m66592-udc: recheck ep->queue after reacquiring lock Ziheng Wei
2026-11-30 10:34 ` [PATCH 2/2] usb: gadget: r8a66597-udc: " Ziheng Wei
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®