Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
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 2/3] media: rkvdec: fix clk reference leak on unbind
Date: Fri,  4 Dec 2026 09:31:21 +0100	[thread overview]
Message-ID: <20261204083123.30740-3-pavone.lawyer@gmail.com> (raw)
In-Reply-To: <20261204083123.30740-1-pavone.lawyer@gmail.com>

From: Jonas Karlman <jonas@kwiboo.se>

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@kwiboo.se>
[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@gmail.com>
---
 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



  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 ` [PATCH v5 1/3] media: rkvdec: split the V4L2 teardown and unregister the devices first Francesco Saverio Pavone
2026-12-04  8:31 ` Francesco Saverio Pavone [this message]
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-3-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