[PATCH v5 0/3] media: rkvdec: fix the clk leaks on unbind
From: Francesco Saverio Pavone
Date: Fri Dec 04 2026 - 03:31:40 EST
Hi,
This is v5, the one Nicolas was waiting for after my self-review of
v4. v4 was a single patch; it is now three.
Patch 1 splits the V4L2 teardown in remove(): the media and video
devices are unregistered first and the V4L2 device is released last.
It is the split I proposed in my reply to v4, moved to the front so
that no step of the series leaves /dev/videoN registered after the
empty IOMMU domain is freed. Patch 2 is Jonas Karlman's fix for the
clock reference leak on unbind, with his authorship, rebased on
patch 1. Patch 3 makes remove() suspend the device also when
something still holds a runtime PM usage count.
Patches 1 and 3 should fix both leaks without patch 2; I did not
measure that combination. I kept patch 2 because it is Jonas's and it
is the smaller fix. Patches 2 and 3 carry the Fixes tag and need
patch 1: without it they call the suspend callback after the driver
data is cleared.
Base: media-committers next at 04b69b3a8acc. Igor Velkov's "Do not
keep the clocks enabled from probe" is not in it yet. I tested with
it applied on top, rebuilt locally from the list posting. With it the
idle enable count is 0, so the v4 numbers (1 -> 2 and 1 -> 1) no
longer apply.
Test: ROCK 5B+ (RK3588), one decoder instance, fdc38000.video-codec,
five clocks. After one unbind while idle and six unbinds with
power/control set to "on", starting from 0, the final clk enable
count is:
base (next + Velkov) 7
patches 1-2 6
patches 1-3 0
An unbind while idle runs remove() with the autosuspend timer still
pending. The base leaves the clocks enabled there, and patch 2 fixes
it: the count is 0 after that unbind with patches 1-2. An unbind with
a usage count held, which is what power/control "on" does, cannot
suspend through autosuspend. That case still leaks one count per
unbind with patches 1-2, and patch 3 fixes it.
With the device active the count reads 2, not 1, because the power
domain also enables the clocks through its pm_clk list (3 on hclk and
aclk, which the IOMMU uses too).
What I did not test:
- No decode was running during any unbind. A job already running
when remove() starts is still not waited for.
- All tests ran with Velkov's change applied; I did not test the
series on plain media next.
- CONFIG_PM=n: not built; arm64 selects PM through ARCH_ROCKCHIP.
With PM=n pm_runtime_force_suspend() is a stub that returns 0.
- I did not exercise the error path of pm_runtime_force_suspend(),
which turns runtime PM back on.
- One board only.
The driver builds with W=1 and no warnings after each patch.
Changes since v4:
- Rebased on media next (04b69b3a8acc).
- Split in three: the teardown split is new patch 1, Jonas's fix is
patch 2, patch 3 is new.
- Dropped the Assisted-by tags. The tools are declared below.
- New measurements, redone on the new base.
v4: https://lore.kernel.org/all/20260717154505.83935-1-pavone.lawyer@xxxxxxxxx/
I used Claude (Anthropic) to draft the commit messages, the code of
patches 1 and 3 and the measurement script. I reviewed every line,
ran the tests on my board and checked the raw counts.
Francesco Saverio Pavone (2):
media: rkvdec: split the V4L2 teardown and unregister the devices
first
media: rkvdec: suspend the device in remove when a usage count is held
Jonas Karlman (1):
media: rkvdec: fix clk reference leak on unbind
drivers/media/platform/rockchip/rkvdec/rkvdec.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
base-commit: 04b69b3a8acc04460cebf03820e2ee1ec77b549b
--
2.54.0