From: Francesco Saverio Pavone <pavone.lawyer@gmail.com>
To: Jonas Karlman <jonas@kwiboo.se>,
Detlev Casanova <detlev.casanova@collabora.com>,
Nicolas Dufresne <nicolas.dufresne@collabora.com>,
Hans Verkuil <hverkuil@kernel.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
Heiko Stuebner <heiko@sntech.de>,
linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v5 1/3] media: rkvdec: split the V4L2 teardown and unregister the devices first
Date: Fri, 4 Dec 2026 09:31:20 +0100 [thread overview]
Message-ID: <20261204083123.30740-2-pavone.lawyer@gmail.com> (raw)
In-Reply-To: <20261204083123.30740-1-pavone.lawyer@gmail.com>
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@gmail.com>
---
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
next prev parent reply other threads:[~2026-12-04 8:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 8:31 [PATCH v5 0/3] media: rkvdec: fix the clk leaks on unbind Francesco Saverio Pavone
2026-12-04 8:31 ` Francesco Saverio Pavone [this message]
2026-12-04 8:31 ` [PATCH v5 2/3] media: rkvdec: fix clk reference leak " Francesco Saverio Pavone
2026-12-04 8:31 ` [PATCH v5 3/3] media: rkvdec: suspend the device in remove when a usage count is held Francesco Saverio Pavone
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204083123.30740-2-pavone.lawyer@gmail.com \
--to=pavone.lawyer@gmail.com \
--cc=detlev.casanova@collabora.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=heiko@sntech.de \
--cc=hverkuil@kernel.org \
--cc=jonas@kwiboo.se \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=mchehab@kernel.org \
--cc=nicolas.dufresne@collabora.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox