Skip to content

Commit 33d7e37

Browse files
Xingxing Luogregkh
authored andcommitted
usb: musb: Get the musb_qh poniter after musb_giveback
When multiple threads are performing USB transmission, musb->lock will be unlocked when musb_giveback is executed. At this time, qh may be released in the dequeue process in other threads, resulting in a wild pointer, so it needs to be here get qh again, and judge whether qh is NULL, and when dequeue, you need to set qh to NULL. Fixes: dbac5d0 ("usb: musb: host: don't start next rx urb if current one failed") Cc: stable@vger.kernel.org Signed-off-by: Xingxing Luo <xingxing.luo@unisoc.com> Link: https://lore.kernel.org/r/20230919033055.14085-1-xingxing.luo@unisoc.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6658a62 commit 33d7e37

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/usb/musb/musb_host.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,16 @@ static void musb_advance_schedule(struct musb *musb, struct urb *urb,
321321
musb_giveback(musb, urb, status);
322322
qh->is_ready = ready;
323323

324+
/*
325+
* musb->lock had been unlocked in musb_giveback, so qh may
326+
* be freed, need to get it again
327+
*/
328+
qh = musb_ep_get_qh(hw_ep, is_in);
329+
324330
/* reclaim resources (and bandwidth) ASAP; deschedule it, and
325331
* invalidate qh as soon as list_empty(&hep->urb_list)
326332
*/
327-
if (list_empty(&qh->hep->urb_list)) {
333+
if (qh && list_empty(&qh->hep->urb_list)) {
328334
struct list_head *head;
329335
struct dma_controller *dma = musb->dma_controller;
330336

@@ -2398,6 +2404,7 @@ static int musb_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
23982404
* and its URB list has emptied, recycle this qh.
23992405
*/
24002406
if (ready && list_empty(&qh->hep->urb_list)) {
2407+
musb_ep_set_qh(qh->hw_ep, is_in, NULL);
24012408
qh->hep->hcpriv = NULL;
24022409
list_del(&qh->ring);
24032410
kfree(qh);

0 commit comments

Comments
 (0)