media: v4l2-mem2mem: cancel job_work in v4l2_m2m_release
Subsystems (2)
PATCH v2 1/1 media: v4l2-mem2mem: cancel job_work in v4l2_m2m_release
v4l2_m2m_release() frees the m2m_dev struct without cancelling m2m_dev->job_work. When a job finishes, v4l2_m2m_schedule_next_job() calls schedule_work() to queue the next run. If the driver tears down concurrently, v4l2_m2m_ctx_release() invokes v4l2_m2m_cancel_job() which handles per-context state (TRANS_RUNNING, TRANS_QUEUED) but does not drain the device-level job_work. A pending work item can then fire after kfree and access freed memory.
Add cancel_work_sync() before the kfree in v4l2_m2m_release() to ensure the work item is drained.
---
Changes in v2:
- Expanded commit message to clarify that cancel_work_sync() complements the per-context v4l2_m2m_cancel_job(), which handles TRANS_RUNNING and TRANS_QUEUED flags but does not drain the device-level work item (Nicolas Dufresne)
drivers/media/v4l2-core/v4l2-mem2mem.c | 1 + 1 file changed, 1 insertion(+)
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);kfree (m2m_dev); }EXPORT_SYMBOL_GPL (v4l2_m2m_release);
Signature · 1 line
2.47.3
Quoted 8 lines · Tristan Madani
v4l2_m2m_release()frees them2m_devstruct without cancellingm2m_dev->job_work. When a job finishes,v4l2_m2m_schedule_next_job()callsschedule_work()to queue the next run. If the driver tears down concurrently,v4l2_m2m_ctx_release()invokesv4l2_m2m_cancel_job()which handles per-context state (TRANS_RUNNING,TRANS_QUEUED) but does not drain the device-leveljob_work. A pending work item can then fire after kfree and access freed memory.
Quoted 6 lines
Add
cancel_work_sync()before the kfree inv4l2_m2m_release()to ensure the work item is drained.Fixes 7f98639def42 ("V4L/DVB: add memory-to-memory device helper framework for videobuf")Signed-off-by Tristan Madani <[email protected]>
This email differs from your gmail address. Which is correct?
Regards,
Hans
Quoted 22 lines
---
Changes in v2:
- Expanded commit message to clarify thatcancel_work_sync()complements the per-contextv4l2_m2m_cancel_job(), which handlesTRANS_RUNNINGandTRANS_QUEUEDflags but does not drain the device-level work item (Nicolas Dufresne)drivers/media/v4l2-core/v4l2-mem2mem.c | 1 + 1 file changed, 1 insertion(+)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);kfree (m2m_dev); }EXPORT_SYMBOL_GPL (v4l2_m2m_release);
From: Tristan Madani <[email protected]>
Quoted 1 line · Hans Verkuil
This email differs from your gmail address. Which is correct?
[email protected] is the correct one. I use [email protected] only as SMTP relay for sending.
Thanks,
Tristan
Hi Hans,
[email protected] is my correct address -- it is in From and Signed-off-by. [email protected] is just the SMTP relay that git-send-email routes through; it leaks into the envelope sender but is not my identity.
Thanks,
Tristan