[PATCH] usb: gadget: f_uac1_legacy: cancel playback_work before freeing audio
From: Tristan Madani
Date: Tue Nov 03 2026 - 19:05:51 EST
From: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>
f_audio_free() frees the f_audio struct without first cancelling
playback_work. If the work function is still running or pending at the
time of the free, it will access freed memory via container_of.
Add cancel_work_sync() before cleanup and deallocation.
Fixes: c6994e6f067c ("USB: gadget: add USB Audio Gadget driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>
---
drivers/usb/gadget/function/f_uac1_legacy.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/usb/gadget/function/f_uac1_legacy.c b/drivers/usb/gadget/function/f_uac1_legacy.c
index 7c8d60c7e87d1..a9807697265c5 100644
--- a/drivers/usb/gadget/function/f_uac1_legacy.c
+++ b/drivers/usb/gadget/function/f_uac1_legacy.c
@@ -943,6 +943,7 @@ static void f_audio_free(struct usb_function *f)
struct f_audio *audio = func_to_audio(f);
struct f_uac1_legacy_opts *opts;
+ cancel_work_sync(&audio->playback_work);
gaudio_cleanup(&audio->card);
opts = container_of(f->fi, struct f_uac1_legacy_opts, func_inst);
kfree(audio);
--
2.47.3