Skip to contentSkip to conversation

media: v4l2-mem2mem: cancel job_work in v4l2_m2m_release

PATCH Superseded Tristan Madani 2 participants 2 messages Oct 24 – Nov 3

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: v4l2-mem2mem: cancel job_work in v4l2_m2m_release

From: Tristan Madani <[email protected]>

v4l2_m2m_release() frees the m2m_dev struct without cancelling m2m_dev->job_work. If a device operation schedules work via v4l2_m2m_try_schedule() and the driver tears down the m2m context concurrently, the work fires on freed memory.

Add cancel_work_sync() before the kfree in v4l2_m2m_release().

Fixes 7f98639def42 ("V4L/DVB: add memory-to-memory device helper framework for videobuf")
---
 drivers/media/v4l2-core/v4l2-mem2mem.c | 1 +
 1 file changed, 1 insertion(+)
drivers/media/v4l2-core/v4l2-mem2mem.c +1 -0
index a65cbb124cfe0..311e2e08d066d 100644
@@ -1207,6 +1207,7 @@ EXPORT_SYMBOL_GPL(v4l2_m2m_init);
 
 void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev)
 {
+	cancel_work_sync(&m2m_dev->job_work);
 	kfree(m2m_dev);
 }
 EXPORT_SYMBOL_GPL(v4l2_m2m_release);
Signature · 1 line
2.47.3
#1 lore raw

Le samedi 24 octobre 2026 à 20:57 +0000, Tristan Madani a écrit :

Quoted 6 lines

From: Tristan Madani <[email protected]>

v4l2_m2m_release() frees the m2m_dev struct without cancelling m2m_dev->job_work. If a device operation schedules work via v4l2_m2m_try_schedule() and the driver tears down the m2m context concurrently, the work fires on freed memory.

How did you tested this ?

Quoted 15 lines

Add cancel_work_sync() before the kfree in v4l2_m2m_release().

Fixes 7f98639def42 ("V4L/DVB: add memory-to-memory device helper framework for videobuf")
---
 drivers/media/v4l2-core/v4l2-mem2mem.c | 1 +
 1 file changed, 1 insertion(+)
drivers/media/v4l2-core/v4l2-mem2mem.c +0 -0
index a65cbb124cfe0..311e2e08d066d 100644

drivers/media/v4l2-core/v4l2-mem2mem.c EXPORT_SYMBOL_GPL(v4l2_m2m_init); · line 1210

Quoted 4 lines
drivers/media/v4l2-core/v4l2-mem2mem.c +1 -0
@@ -1207,6 +1207,7 @@ EXPORT_SYMBOL_GPL(v4l2_m2m_init);
 
 void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev)
 {
+	cancel_work_sync(&m2m_dev->job_work);

Seems quite insufficient if you compare with the actual implementation in v4l2_m2m_cancel_job(). Is it really possible to call this without having released (closed) all the context first ?

Nicolas

Quoted 3 lines
drivers/media/v4l2-core/v4l2-mem2mem.c +0 -0
 	kfree(m2m_dev);
 }
 EXPORT_SYMBOL_GPL(v4l2_m2m_release);