[PATCH v5 2/3] media: rkvdec: fix clk reference leak on unbind

From: Francesco Saverio Pavone

Date: Fri Dec 04 2026 - 03:31:45 EST


From: Jonas Karlman <jonas@xxxxxxxxx>

remove() calls pm_runtime_disable() before
pm_runtime_dont_use_autosuspend(), so the second call can never suspend
the device: it reaches rpm_idle(), which returns -EACCES once PM runtime
is disabled. The probe error path has had the two the other way round
since the driver was merged.

This shows up when the device is unbound while the 100ms autosuspend
window is still open, which is what an rmmod right after a decode does.
device_release_driver() calls pm_runtime_put_sync() before .remove(),
and rpm_idle() adds RPM_AUTO on its own, so that put only arms the
autosuspend timer. pm_runtime_disable() then cancels the timer, and
pm_runtime_reinit() relabels the device suspended without calling the
driver back. The clk_bulk reference taken by rkvdec_runtime_resume() is
never dropped, and a later probe does not reclaim it, so every such
unbind leaks one enable count.

Drop autosuspend first, so the callback still runs and drops the
reference rkvdec_runtime_resume() took.

The callback needs the driver data, which v4l2_device_unregister()
clears. The previous patch moved that call to the end of remove(), so
the callback can run here. Swapping the two PM calls without it oopses
whenever the device is still active at unbind.

Fixes: cd33c830448b ("media: rkvdec: Add the rkvdec driver")
Signed-off-by: Jonas Karlman <jonas@xxxxxxxxx>
[fsp: moved pm_runtime_disable() below iommu_domain_free() to fit the
teardown split, wrote the commit message]
Signed-off-by: Francesco Saverio Pavone <pavone.lawyer@xxxxxxxxx>
---
drivers/media/platform/rockchip/rkvdec/rkvdec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.c b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
index 262ff6a407986..8a0967f6f6895 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec.c
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
@@ -1903,12 +1903,12 @@ static void rkvdec_remove(struct platform_device *pdev)

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);

+ pm_runtime_disable(&pdev->dev);
rkvdec_v4l2_release(rkvdec);
}

--
2.54.0