[PATCH 6/7] media: s5p-mfc: allow subscribing to control events

Shigeaki Asai via B4 Relay devnull+y-asai.0816.docomonet.jp at kernel.org
Mon Nov 30 05:02:37 PST 2026


From: Shigeaki Asai <y-asai.0816 at docomonet.jp>

The decoder has controls, but vidioc_subscribe_event() only accepts
V4L2_EVENT_EOS and V4L2_EVENT_SOURCE_CHANGE, so subscribing to control
events fails with -EINVAL. v4l2-compliance reports:

  fail: v4l2-test-controls.cpp(1128): subscribe event for control 'User Controls' failed
  test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: FAIL
  fail: v4l2-test-time32-64.cpp(141): doioctl(node, VIDIOC_SUBSCRIBE_EVENT, &sub)
  test TIME32/64: FAIL

Handle V4L2_EVENT_CTRL with v4l2_ctrl_subscribe_event(). The file
handle already points to the control handler of the context.

Control events are removed in v4l2_fh_exit(), which looks up the
controls in the handler, so free the control handler after
v4l2_fh_exit() in s5p_mfc_release(). Otherwise closing the device after
subscribing to a control event uses the freed handler:

  WARNING: kernel/locking/mutex.c:625 at __mutex_lock+0xba8/0x1088
  DEBUG_LOCKS_WARN_ON(lock->magic != lock)
   v4l2_ctrl_find [videodev] from v4l2_ctrl_del_event+0x1c/0x78 [videodev]
   ...
   v4l2_fh_exit [videodev] from s5p_mfc_release+0xfc/0x25c [s5p_mfc]

Tested on an ODROID-XU4 (Exynos5422) with Kodi/FFmpeg and
v4l2-compliance 1.32.0 on a 7.3.4 kernel (LibreELEC).

The problem was investigated and this patch was prepared with the help
of Claude (AI).

Signed-off-by: Shigeaki Asai <y-asai.0816 at docomonet.jp>
---
 drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c     | 2 +-
 drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
index ea0fbf970340..0450c762e5ac 100644
--- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
@@ -1018,11 +1018,11 @@ static int s5p_mfc_release(struct file *file)
 	}
 	if (dev)
 		dev->ctx[ctx->num] = NULL;
-	s5p_mfc_dec_ctrls_delete(ctx);
 	v4l2_fh_del(&ctx->fh, file);
 	/* vdev is gone if dev is null */
 	if (dev)
 		v4l2_fh_exit(&ctx->fh);
+	s5p_mfc_dec_ctrls_delete(ctx);
 	kfree(ctx);
 	mfc_debug_leave();
 	if (dev)
diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
index 99df8f5e36c8..6b52617254d9 100644
--- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
@@ -939,6 +939,8 @@ static int vidioc_subscribe_event(struct v4l2_fh *fh,
 		return v4l2_event_subscribe(fh, sub, 2, NULL);
 	case V4L2_EVENT_SOURCE_CHANGE:
 		return v4l2_src_change_event_subscribe(fh, sub);
+	case V4L2_EVENT_CTRL:
+		return v4l2_ctrl_subscribe_event(fh, sub);
 	default:
 		return -EINVAL;
 	}

-- 
2.43.0





More information about the linux-arm-kernel mailing list