[PATCH v2 1/2] scsi: ufs-mediatek: use devm_regulator_get() for the va09 regulator
From: Xiangwu Lai
Date: Tue Nov 17 2026 - 22:20:31 EST
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")
Signed-off-by: Xiangwu Lai <laixiangwu@xxxxxxxxxxxxxxxxxxxx>
---
Changes in v2:
- Keep devm_regulator_get() and additionally add an .exit callback
that powers the M-PHY off, so the va09 enable count is balanced
before the devm release. Without it, _regulator_put() would hit
WARN_ON(regulator->enable_count) on every driver unbind, since
ufs_mtk_init() leaves the regulator enabled (reported by Sashiko
AI review).
Link: https://lore.kernel.org/r/20261118014234.424-1-laixiangwu@xxxxxxxxxxxxxxxxxxxx
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 5b6bff2cf..ebbc017d0 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.50.1.windows.1