[PATCH media] media: cx231xx: cancel module loading work on probe failure
From: Xinsheng Zhu
Date: Sun Nov 15 2026 - 22:52:08 EST
cx231xx_usb_probe() schedules asynchronous module loading before
creating and registering the media controller graph. If either
operation fails, the probe error path releases device resources
without canceling the pending work.
The work callback accesses the device structure to determine which
modules to load. Since the device structure is devm-allocated,
a failed probe may free it while the work is still pending or
running, potentially leading to a use-after-free.
Cancel the module loading work synchronously before releasing
device resources on probe failure. This ensures that the work
cannot access the device structure after it has been freed.
Signed-off-by: Xinsheng Zhu <xinsheng.zhu.ny@xxxxxxxxx>
---
drivers/media/usb/cx231xx/cx231xx-cards.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index b0941cd2a2d8..f8ed894ac0ed 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1533,12 +1533,18 @@ static void request_modules(struct cx231xx *dev)
schedule_work(&dev->request_module_wk);
}
+static void cancel_request_modules(struct cx231xx *dev)
+{
+ cancel_work_sync(&dev->request_module_wk);
+}
+
static void flush_request_modules(struct cx231xx *dev)
{
flush_work(&dev->request_module_wk);
}
#else
#define request_modules(dev)
+#define cancel_request_modules(dev)
#define flush_request_modules(dev)
#endif /* CONFIG_MODULES */
@@ -1900,8 +1906,12 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
if (!retval)
retval = media_device_register(dev->media_dev);
#endif
- if (retval < 0)
+ if (retval < 0) {
+ cancel_request_modules(dev);
+ cx231xx_close_extension(dev);
cx231xx_release_resources(dev);
+ usb_set_intfdata(interface, NULL);
+ }
return retval;
err_video_alt:
base-commit: 48fe5a7834cc10081887d7bcd9ff0a4cadc3fa8c
--
2.54.0 (Apple Git-157)