Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796373095; b=5b8Kt2WQapkAv7DvkX6PEUKt5I0/iE0gEYndParBqlP6fPEX+g/7qdsUgE43Mp2OOIpB lyka0g6sworEjDUhgQq7FhIhGbJpmcRgKCX1ZBCUzreEz/tUnrTYktNRxzLaIVuFEqG/m 09N2lQs6YZYitPuXD9h38C4wh0zZGaE/LPy1BWI7d6fr/y0IHNS+4XgN9dVu1Of4PZ7a1 /ziIXtIl3eXZcHnWTXDAhlLUCUYoJhPc06Hy5R1qgC90/SlP3idgqDPecvi1j6NZ+rxuj dYb2Q+OVoJErw74ZNJ+a3VfCOIWiN1ZYpAvfiV9o85WPyJZA0s2DjDccrTpr/uYZASA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796373095; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=gqtxA7d6OCUb18Xg9N/EPJlmenw1U49klpFErVbaBYQ=; b=j4Bpfo/8sNUEIJqIknasao2TU2C9OG+GsDVHm6hUq+RNHvMGld8qkB4JS+SPJCTDsUc2 sovdMYRR/01TfDt4Kqv2t2BqvKWdY+BWTHU8ybekD9C89GmMprxsYapG+WzXqwEO+zYIJ L+DqYfHYM3po1FRhbRKTyF3k4DsntSUyhtwYfPjVhJlYMV17/opqY8GJpFykdV98WXV78 oOjFC4cC4hr7ohhAVEOOCAhma0RM6adK1fFYtgDOgMLzG81UdQtxjonEtjapy2f9gBrKH Pl21dqoh2R8P98WBPGAS2wvi/7Uz7cUKR7WghjkQMZ92W3UBhDm/r4fdQqz189R6iMg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=hmiSlOjN; arc=none smtp.remote-ip=209.85.128.49 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A32C606A32C for ; Fri, 4 Dec 2026 08:31:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6A32C606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=hmiSlOjN Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4bb6c7b6dbdso5949805e9.0 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=vger.kernel.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=hmiSlOjNdQx4O51wVa58hPMlAavqliEU3lY20Yid+u4JRsv9M48owsFpjunJUeS41l IvcLYwp5K5pVSemdIyVF7/yp5sPO5hZYpcjQdybAtK1ShwyZph9qkUqnS0pV782N13Bk 5PDFQkjp0+k+IvPAYhF2lWrQt4pNRdzvbaYCe9Nw3kd18ZY5vSs7e4sVPdOehGcxq18y PaLYKWaciWDdx2/fl3Oqy0DVzRuOWobUxZpBj03rN/DYAWkMVGGZSybtsuiv13bsrG89 ZNhmUf2jQRTeP+oklT+9tYfD7yQEAEqQmY+XubLSPlic5KflPuuWBtsVmgJ1MwuJKqVB 2jRQ== 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=Us2V8Lf1WErJpYm51MAOQAQm5cmm7v++LNu+ONvGHZ1pK4C9m4EXI0Km9sENMdFqpE w1czLAYSSfr1AxYMrB9p6uS2i/iZk0buRk97rHDf59l16jz4N0Kmqiho1weE1LzW2W6E G0Twt4YGxodAdJ2r8ebvi7nOaGgFTQDc96qOr2G1qzakw2RUUXSMJ7DuiT/a+PSfROgV uSLoDicq9u0dW+Db99ZkI8XSgpM23Ym9IP+l75FIUXwaT0lLvU84x4ADOCVAnQy6cqnd eCP0omOv3rEi1E1SnK68TYMj96oypQHSGJxP3RdWhPEaMpTse5EFTIi0QBkQ3u6ja8or jK6A== X-Forwarded-Encrypted: i=1; AL+hErGb8BrLTJ+5Sfr46Gw63kul1APCwTFAaNS2UikCH8r65nqeX/k+9EwawRahI+VfLxRFxcNi17UERfugtQ==@vger.kernel.org X-Gm-Message-State: APuU4Z/fg2Wervi3qhbOWNS/ReF/fM76gGaB03AyU2rzFutxTa5eudll t/D1u4e62auRdn7nAu4Clf0RTYwAVkj8wLx/Gd9O3tJD+t8jXwZxPPI= X-Gm-Gg: AZFdTZcNu7aAfAicnml5DyviuYPkWrt2Hxe7AKmtCNUW8AqNo5fiWNMpVB0fhkpdbii KeTzES4IUwj5YjRTatnUNmoS2Cut6MWcnuAQ9lQzSDjMzuXp+BekM00GXLxLAJohzRYNWA0/elU T+s5tuqk1Jg+u7PeISdZUGbr4yBCDH8HpKvEJrTbCBhhIEhiyrMA7IQ/iFI5qJ6u/N/K/BMMQK/ Kj4pnq0ZO0p3AERM72hzrtaAl11naj1A/nrfpnxt3EiDWtHZqF++/jGE95j2TcnyH9g7DHTG9qr BIY7lzP3hSX2hp9x7ssz+k7X5+23f0mRCX+oMtiplyifMI/frZ5I1at4Gngbk+t9ar7MHcp66x3 wv57mrS3h10ZBzVmr8kDKawiPGY7nQ9eJj7pKUxUiLlGW038kCZ3gvlAeSj8HBeTtr+9BuVIPMx a1ECexwoKoNTcMvwUmPje1w/pviznjqAI/KNvKVCIUYrPatnts8BY2snvbTVa1yBUuJp7MVD5vn 2BXXjpxagKtAIOOFM1Tq/zX7yXCz6spPlORX7zZmGN71Ydun8xivNl9w34apC6HcZgET/7Y4kPo E4U/It4NlnUHxkXCSFcpiNaVVK0buQ37i8EHCj8JTCdv1ttSLQmzb9LuKUMloKf5zS9Pv1fjzRD 1N/ucXtU8FsEke5Z4 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-Mailing-List: linux-media@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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