From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380319; b=Jb+7GefsbtuxOLUZS9kleqNupfP9wrOQVg7P+KIxKZhnT3qZuPYz3kFelL8Iq/jIKl0J S2mRXprUNz9Ba95SuyjcqskREnlOnfhgf1je5hh9Z3hGVQRj7GJ2ihFkYuzX3Z6mLvMZD nLPC+xJznRgQSNCEqz8oD0kadq2PckZ9qus4zXch++kyEMaOS/RYD3XUFGkWx50v4wymv 9Onc1CCId5xpZYNHojFafPw6VvU23wSrDnSEIrqjHLITvqi3nMIPslVItpTSMcEDHelQD Fq6ej4nrWkAMQE3hWpL8ljW8hRRYDRKIFvF+iX/T36YEsdBx5uAYQ+MnddYgKcTs1Vw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380319; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=ObEyvGNMpxXGq1/d3POjz4s1bqFqTmtPk6GXFI7nM4I=; b=AlllFiLvTIG6g9xHMLW/czgFjL7B0Wp65v5/Ib5nqE0UmPozSr+aZRSQpZztvxOIQoaJ hEOkda+TbxNDRwbP34KVLt2dVsG/iVB+gHT9kbYyBtn/8/o+QorE5fsSXHhriGlYH5Qu8 2POalFoAdkelKgPEtCOK9xJp2cZ+01hAO4yo77ZuN3riEFgX4ox63ZP/WWgd0QGGkSNc9 CEEqHAmpQfXvY5qc9/p4mhYdLju4I0rX6PsTEVVzeISjdoL1ZnrUm5eY32SAXHZ7QUEf2 B7k1JDJnGCoqMgRrJDpI3W9M3HLog/ncvyMRaUfKL0/3h69e2hJVwxKIf+2KWEoqDXw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=EaTHnMw6; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9975A606A322; Fri, 4 Dec 2026 10:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=EaTHnMw6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 165BC1F00931; Fri, 4 Dec 2026 10:31:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380319; bh=ObEyvGNMpxXGq1/d3POjz4s1bqFqTmtPk6GXFI7nM4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EaTHnMw6p+0YCOIUwVN0oxztjuuHHLpxS9iiUK633V+9xVTeSb7g8+Qy2Zs82IK4T AlkQbtN74tE1v0muyRcgQg0wSknBRitL5J4Pc3uFZ/OWMkptetR9TvwjNgHgT7wsHE BOMXja0nGz/py8PZ+Ud7oYMnTOEzyRlf4xAXnx2Y= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Peter Wang , Xiangwu Lai , "Martin K. Petersen (Oracle)" , Sasha Levin Subject: [PATCH 7.3 181/742] scsi: ufs-mediatek: Use devm_regulator_get() for the va09 regulator Date: Fri, 4 Dec 2026 19:00:45 +0900 Message-ID: <20261204100639.891192206@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Xiangwu Lai [ Upstream commit def1745a6a8bc44b39e8670c737c27fd38b3595c ] ufs_mtk_init_va09_pwr_ctrl() obtains the va09 regulator with regulator_get() but the reference is never released with regulator_put(), neither on driver unbind nor on probe failure. The other regulators handled by this driver (dvfsrc-vcore) are already obtained with devm_regulator_get_optional(). Use devm_regulator_get() so that the reference is released automatically when the UFS device is detached. This alone is not enough, though: ufs_mtk_init() powers the M-PHY on, which enables the va09 regulator, and nothing powers it off again on the way out. The variant operations have no .exit callback and ufshcd_pltfrm_remove() only resumes the device. The devm release would then hit WARN_ON(regulator->enable_count) in _regulator_put() and leak the enable reference. Balance the use count by adding an .exit callback which powers the M-PHY off, in the same spirit as the .exit callbacks of ufs-exynos and ufs-qcom. ufshcd_hba_exit() invokes it both on driver unbind and on ufshcd_init() failure after the variant init, so the enable count is always balanced by the time devm releases the regulator. It relies on the state tracking in ufs_mtk_mphy_power_on() and is a no-op if the M-PHY was never powered on. Fixes: cf137b3ea49a ("scsi: ufs-mediatek: Support VA09 regulator operations") Reviewed-by: Peter Wang Signed-off-by: Xiangwu Lai Link: https://patch.msgid.link/20261119071611.117-2-laixiangwu@cmss.chinamobile.com Signed-off-by: Martin K. Petersen (Oracle) Signed-off-by: Sasha Levin --- drivers/ufs/host/ufs-mediatek.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c index ff0a661c14305..1a854a706c9ba 100644 --- a/drivers/ufs/host/ufs-mediatek.c +++ b/drivers/ufs/host/ufs-mediatek.c @@ -692,7 +692,7 @@ static void ufs_mtk_init_va09_pwr_ctrl(struct ufs_hba *hba) { struct ufs_mtk_host *host = ufshcd_get_variant(hba); - host->reg_va09 = regulator_get(hba->dev, "va09"); + host->reg_va09 = devm_regulator_get(hba->dev, "va09"); if (IS_ERR(host->reg_va09)) dev_info(hba->dev, "failed to get va09"); else @@ -1331,6 +1331,14 @@ static int ufs_mtk_init(struct ufs_hba *hba) return err; } +static void ufs_mtk_exit(struct ufs_hba *hba) +{ + struct ufs_mtk_host *host = ufshcd_get_variant(hba); + + if (host) + ufs_mtk_mphy_power_on(hba, false); +} + static int ufs_mtk_negotiate_pwr_mode(struct ufs_hba *hba, const struct ufs_pa_layer_attr *dev_max_params, struct ufs_pa_layer_attr *dev_req_params) @@ -2353,6 +2361,7 @@ static void ufs_mtk_config_scsi_dev(struct scsi_device *sdev) static const struct ufs_hba_variant_ops ufs_hba_mtk_vops = { .name = "mediatek.ufshci", .init = ufs_mtk_init, + .exit = ufs_mtk_exit, .get_ufs_hci_version = ufs_mtk_get_ufs_hci_version, .setup_clocks = ufs_mtk_setup_clocks, .hce_enable_notify = ufs_mtk_hce_enable_notify, -- 2.53.0