[PATCH v5 1/3] media: rkvdec: split the V4L2 teardown and unregister the devices first
From: Francesco Saverio Pavone
Date: Fri Dec 04 2026 - 03:31:46 EST
rkvdec_remove() tears the whole V4L2 side down in one call, before
runtime PM is disabled and the empty IOMMU domain is freed.
The next patch lets the runtime suspend callback run during remove().
rkvdec_runtime_suspend() looks its state up with dev_get_drvdata(), and
v4l2_device_unregister() clears it: struct rkvdec_dev has v4l2_device
as its first member, so &rkvdec->v4l2_dev and rkvdec are the same
address and the check in v4l2_device_disconnect() matches. The V4L2
device therefore has to be released after the PM teardown.
Moving all of rkvdec_v4l2_cleanup() there would leave /dev/videoN
registered while the empty IOMMU domain is freed, and a job queued in
that window would reach rkvdec_iommu_restore() with a freed domain.
Split the teardown instead. Unregister the media and video devices
first, which stops new ioctls from queueing jobs, and release the m2m
and V4L2 devices last. The PM calls stay as they are.
Signed-off-by: Francesco Saverio Pavone <pavone.lawyer@xxxxxxxxx>
---
drivers/media/platform/rockchip/rkvdec/rkvdec.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.c b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
index 6cd7445b18c45..262ff6a407986 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec.c
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
@@ -1432,11 +1432,15 @@ static int rkvdec_v4l2_init(struct rkvdec_dev *rkvdec)
return ret;
}
-static void rkvdec_v4l2_cleanup(struct rkvdec_dev *rkvdec)
+static void rkvdec_v4l2_unregister(struct rkvdec_dev *rkvdec)
{
media_device_unregister(&rkvdec->mdev);
v4l2_m2m_unregister_media_controller(rkvdec->m2m_dev);
video_unregister_device(&rkvdec->vdev);
+}
+
+static void rkvdec_v4l2_release(struct rkvdec_dev *rkvdec)
+{
media_device_cleanup(&rkvdec->mdev);
v4l2_m2m_release(rkvdec->m2m_dev);
v4l2_device_unregister(&rkvdec->v4l2_dev);
@@ -1897,12 +1901,15 @@ static void rkvdec_remove(struct platform_device *pdev)
cancel_delayed_work_sync(&rkvdec->watchdog_work);
- rkvdec_v4l2_cleanup(rkvdec);
+ rkvdec_v4l2_unregister(rkvdec);
+
pm_runtime_disable(&pdev->dev);
pm_runtime_dont_use_autosuspend(&pdev->dev);
if (rkvdec->empty_domain)
iommu_domain_free(rkvdec->empty_domain);
+
+ rkvdec_v4l2_release(rkvdec);
}
static int rkvdec_runtime_resume(struct device *dev)
--
2.54.0