From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796373095; b=UmDioGUp38PKkaEnMT3WHQCx7reTaSHW1iv0LvRsXNVTPuzihv0i375wXBaa55BM9WwG 4Y3YLRvMvwqHwhcXdxavvorEveB8dbQB3ydGnZTnPDgVEFOMEgJY2aZas1fvsFCmlNhtp nPOmxj86Dm9pncgrdaqRQdIiabT1kSCI8Kkbi8+Yw6HBh7JibydvWZr6QisJAeJC6zoFU rmxmT9/OIsBknMyrqYChcmq8jhowUnPG9PmYSjnbhQZAkL+8NN6YRCu2IrZXdw3GYl6hX US4L6EvHKoMst/KlyS/pkztctl9x90VXvt5uc6+2DvMBsT9ii836mwRybRloxc3h3fg== 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=FWsYA/ltQoZP2066XywhjnF0jtuNylUHbPu0/fM79wfiQsBfFPRkjs62RqYqxBp7eHW2 pgRIaZamD3E8v/X74DmXBBXUAND/Pj/NO4UeUTbdO02G6IAJZhZKiNNDeOoRYcZ+CCTb1 6BTptuLWPXM/R9CP9zzSYPdSVyq4H0TXjcU9SMOikwr+6L9VF3PZGobe6CjjOlvXFHzk9 +eaAB8sKRmigfbXPcon2xip6r2UxsezS85PeaTOgIka5gAq8Ze8Qtfz3GABxXp4lXeJGT LBNLv+uJxrjuF14HAno3Nynk51abRwBLqU4GxINNR7LAjTlu4z9MBEpoBcX1CTAZC9A== 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.221.45 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 7BF34606A32D for ; Fri, 4 Dec 2026 08:31:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7BF34606A32D 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) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=hmiSlOjN Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-4acb44dcd7bso740683f8f.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=0+Q5dQdWy5n5RhYIGVWT6iE+yaQ/ekL/1GbumCwkjA6PfnEd9EcQcf81waDkYgLbb3 THX6Y0Ae+Tbh2CgEKGLGUYDwG4oCDWs9Diw9xCJFhFxSMqKJ9kkb++wnlPlBc0fq6vXm gdTpHqU0RDztgNLl2T398EkwlwgOSCnv8/vQSyZyeFyv9ZeL8sfWPpIl9QtDbIS/zP96 d4scuE7DfDrAXEgK2Hfshk+wZJm47w5k8oeeXYYAATn4cVkeYZUdkKiefRQ6dkhOxihS tnlyrGAR3P9iZtR+hNv1QZyMfHYiJstG/p29MU3ruwcog4THwxwLhnAWFcrcAyRrof9M tWsA== X-Forwarded-Encrypted: i=1; AL+hErEGnm5234FuQKl6+FRtO3a11NkyqT5ULFglc4njF7EX+VcXWCwtmOR1qMLpZaY8qfmeoChpbgGP64Vh3gc=@vger.kernel.org X-Gm-Message-State: APuU4Z+BKFs6m/n9+TbUuYG5KS3wQTVATmLM+QjVoHny3lYvUYRAaOug B9pbemnkf1i90cRLXAbEzxejpI2PbjaQrRvWBSUts2MOTnV5fDbo8E0= X-Gm-Gg: AZFdTZfVocOGeL01VP+fvV3/iOUfB+ufzixo4wzeocxwTaCGNSPa4aJ+0aRektBPInv 8YKDYvHDHrXVYxrjgat7pwl7o1/ls8s9I/vbPtABNC4FBrPX/CQgfrmDM/PF8AMZyHV/Sq+pXk9 2OxyL8mOhMx4p5JTnPCG93LAD2VKDFLh1FkDkboa7GTNt03Mi2NkP1In98blh8Wn09u8VSosTl1 T9go5TL6HY1VjQVVlUE7yw8q8B7xWwvmvRzdkn63UCrgn5dFxC6VvYCNgiifjy7OrUZef0zmnwV qDjZQNCuUeBviNDgGN2pohZuKoom4IvxX7fhEW+jel6RnePWvZQRfLi1VzO7iwLiP96zJdL2OiG URmPHuAiuEyyr1/IIHb3TTl3bwj3GXK9bwjP0pAt5loPLGhuQgX4Louk/xToz/GtY1VWMwROr0U IHvQq4CRUv8AoKZfNA4YePlGrZMYnegQPXsEBGQAS1zyECEe17uGkc7hp1fAUvXHCybsRBOTRnf Te4yijulW5sEPHcY/YrI2CgdZnT4L40ctgKND6hZcWor0F8MpAz3ro7/RbLMDQl9iZTLmNI1X/S Eq5FpCvV6+V+sfDxK6Mf4PiDgoeb9gEE8J+drpOmZcxsP4F2yShdwDtzP9oH5t0WOzlh0FtzYpH Nlx9f/oKT8kZb1fY7 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-kernel@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