Skip to content

Commit 068fdad

Browse files
jbrun3tgregkh
authored andcommitted
usb: gadget: u_audio: fix race condition on endpoint stop
If the endpoint completion callback is call right after the ep_enabled flag is cleared and before usb_ep_dequeue() is call, we could do a double free on the request and the associated buffer. Fix this by clearing ep_enabled after all the endpoint requests have been dequeued. Fixes: 7de8681 ("usb: gadget: u_audio: Free requests only after callback") Cc: stable <[email protected]> Reported-by: Thinh Nguyen <[email protected]> Signed-off-by: Jerome Brunet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 75432ba commit 068fdad

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/usb/gadget/function/u_audio.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,6 @@ static inline void free_ep(struct uac_rtd_params *prm, struct usb_ep *ep)
394394
if (!prm->ep_enabled)
395395
return;
396396

397-
prm->ep_enabled = false;
398-
399397
audio_dev = uac->audio_dev;
400398
params = &audio_dev->params;
401399

@@ -413,6 +411,8 @@ static inline void free_ep(struct uac_rtd_params *prm, struct usb_ep *ep)
413411
}
414412
}
415413

414+
prm->ep_enabled = false;
415+
416416
if (usb_ep_disable(ep))
417417
dev_err(uac->card->dev, "%s:%d Error!\n", __func__, __LINE__);
418418
}
@@ -424,8 +424,6 @@ static inline void free_ep_fback(struct uac_rtd_params *prm, struct usb_ep *ep)
424424
if (!prm->fb_ep_enabled)
425425
return;
426426

427-
prm->fb_ep_enabled = false;
428-
429427
if (prm->req_fback) {
430428
if (usb_ep_dequeue(ep, prm->req_fback)) {
431429
kfree(prm->req_fback->buf);
@@ -434,6 +432,8 @@ static inline void free_ep_fback(struct uac_rtd_params *prm, struct usb_ep *ep)
434432
prm->req_fback = NULL;
435433
}
436434

435+
prm->fb_ep_enabled = false;
436+
437437
if (usb_ep_disable(ep))
438438
dev_err(uac->card->dev, "%s:%d Error!\n", __func__, __LINE__);
439439
}

0 commit comments

Comments
 (0)