Re: [PATCH v2 1/2] scsi: ufs-mediatek: use devm_regulator_get() for the va09 regulator
From: Peter Wang
Date: Wed Nov 18 2026 - 22:54:41 EST
On Wed, 2026-11-18 at 11:20 +0800, Xiangwu Lai wrote:
> 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>
> ---
Hi Xiangwu,
Thanks for fix this bug.
Reviewed-by: Peter Wang <peter.wang@xxxxxxxxxxxx>