[PATCH media v2] media: cx231xx: cancel module loading work on probe failure
From: Xinsheng Zhu
Date: Mon Nov 16 2026 - 00:27:34 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.
Fixes: ab232e46bf01 ("[media] cx231xx: enforce check for graph creation")
Signed-off-by: Xinsheng Zhu <xinsheng.zhu.ny@xxxxxxxxx>
---
Changes in v2:
- Add a Fixes tag.
- Reuse the existing err_video_alt cleanup path instead of
duplicating resource teardown.
v1: https://lore.kernel.org/linux-media/20261116035159.40755-1-xinsheng.zhu.ny@xxxxxxxxx/
drivers/media/usb/cx231xx/cx231xx-cards.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index b0941cd2a2d8..e24c2999687e 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,10 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
if (!retval)
retval = media_device_register(dev->media_dev);
#endif
- if (retval < 0)
- cx231xx_release_resources(dev);
+ if (retval < 0) {
+ cancel_request_modules(dev);
+ goto err_video_alt;
+ }
return retval;
err_video_alt:
base-commit: 48fe5a7834cc10081887d7bcd9ff0a4cadc3fa8c
--
2.54.0 (Apple Git-157)