From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 422FA606A322 for ; Fri, 4 Dec 2026 08:32:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=adYLiCJ5; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=wvXjBnhB DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Unsubscribe-Post:List-Owner; bh=gqtxA7d6OCUb18Xg9N/EPJlmenw1U49klpFErVbaBYQ=; b=adYLiCJ5MlOFl3pim2xN/c9LSu im5XrcCJhJfamMEKN7/9n4XaHEitVfMBxwZptUx+KKo3LLeDLk/b8XeRrPdpkeEiknYusbqD7f+2A AshwWUYQ+xC6ZmYQYuHoaY6E9wOvoyClwBsl85zeSdNrYlQ65sgT6hTQXG65GNx98AT8uTnCmoDrf 6tmOifR4p4TBDSnacSNg30HJD9ZMYS2e2QO87cGf9cK6e1nmy2CMmapVNnKXukPc32Y4sh2x5OYit yy3kRaW4x8g2eAPjo97IW6F+qw2/2SS99injvi8rJdkhFRWqDTKemQwjBCHbLsViGH/TpO9qxfDTt KzUOJEWA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZOhs-0000000H8Y7-3CY5; Fri, 04 Dec 2026 08:31:52 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZOhb-0000000H8QS-3XrJ for linux-arm-kernel@lists.infradead.org; Fri, 04 Dec 2026 08:31:45 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4bb64c99d2fso5069075e9.3 for ; Fri, 04 Dec 2026 00:31:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796373094; x=1796977894; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=gqtxA7d6OCUb18Xg9N/EPJlmenw1U49klpFErVbaBYQ=; b=wvXjBnhBGyQaVUJgTtyFaxYjWiCMWKfGrLKMEEu42HA2+6e2dTR4hwkgl7LobwRcmF Wnck4fU69I1Gm80L5ayjUI39OjmGnPw0fg1TvKvCaZJIpLZUpmsreoCJL2pU9B5eE6w8 BU8lTRnpUzCU5iOldS4qCcK7r8w07XbOholmmPTBh4TJK1QBkW6fXaklk8iO9icRvLi6 b6Z+moUinRmXLp4vgbPfpZZpUYqwQoR1ie8C4covOERPqjSw4i9VIdOVaol66mvfZdpm fXtB7m4qMqLQRsvl17HuooddonkXkZ1V6dKOvtB15c4l44koY1FhSx7yIgTCxoTe7lly pbag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796373094; x=1796977894; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=gqtxA7d6OCUb18Xg9N/EPJlmenw1U49klpFErVbaBYQ=; b=jX/KBRZDlSqwGojcyKU2Q7Pd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iVSy/s7tfQIBCV9Sz7b9DryNU3k oXY/x/VRVuMIksOCFHbEj/SJUopLEd7kwR5uLxG50nEDy3X/rQnUnRvbWHvkZDW7QhSYKJgBDs+ tHRHAoopkKN0sSlYLRLlMFTXpxLNKK25aMHHRHmpsftuuDzIO1iivp2lxaJQnI8g8nIXjIUdIQ+ FL2e93itp8PPn6Uvk X-Received: by 2002:a05:600c:4f84:b0:4bb:60bd:5398 with SMTP id 5b1f17b1804b1-4bbeb879e9dmr22908125e9.10.1796373093665; Fri, 04 Dec 2026 00:31:33 -0800 (PST) Received: from localhost.localdomain ([151.57.87.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe00792c9sm144669115e9.3.2026.12.04.00.31.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 04 Dec 2026 00:31:33 -0800 (PST) From: Francesco Saverio Pavone To: Jonas Karlman , Detlev Casanova , Nicolas Dufresne , Hans Verkuil , Mauro Carvalho Chehab Cc: Ezequiel Garcia , Heiko Stuebner , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 0/3] media: rkvdec: fix the clk leaks on unbind Date: Fri, 4 Dec 2026 09:31:19 +0100 Message-ID: <20261204083123.30740-1-pavone.lawyer@gmail.com> X-Mailer: git-send-email 2.56.1 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261204_003136_713045_3E3F5AC6 X-CRM114-Status: GOOD ( 22.10 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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@gmail.com/ 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