Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs-mediatek: use devm_regulator_get() for the va09 regulator
@ 2026-11-18  1:42 Xiangwu Lai
  2026-11-18  1:54 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Xiangwu Lai @ 2026-11-18  1:42 UTC (permalink / raw)
  To: peter.wang, chaotian.jing
  Cc: chu.stanley, alim.akhtar, bvanassche, stanley.chu, linux-scsi,
	linux-mediatek, linux-kernel, Xiangwu Lai

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.

Fixes: cf137b3ea49a ("scsi: ufs-mediatek: Support VA09 regulator operations")
Signed-off-by: Xiangwu Lai <laixiangwu@cmss.chinamobile.com>
---
 drivers/ufs/host/ufs-mediatek.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
index 5b6bff2cf..426af10b3 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
-- 
2.50.1.windows.1




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] scsi: ufs-mediatek: use devm_regulator_get() for the va09 regulator
  2026-11-18  1:42 [PATCH] scsi: ufs-mediatek: use devm_regulator_get() for the va09 regulator Xiangwu Lai
@ 2026-11-18  1:54 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-18  1:54 UTC (permalink / raw)
  To: Xiangwu Lai; +Cc: linux-scsi

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] scsi: ufs-mediatek: unbalanced va09 enable count on devm
  regulator release
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] scsi: ufs: mediatek: state mismatch on regulator failure in
  ufs_mtk_mphy_power_on() [1]
--

commit d21747583e36bae96677aff04541a8dd783fc43c
Author: Xiangwu Lai <laixiangwu@cmss.chinamobile.com>

scsi: ufs-mediatek: use devm_regulator_get() for the va09 regulator

This commit switches ufs_mtk_init_va09_pwr_ctrl() from regulator_get() to
devm_regulator_get() so the va09 regulator reference is released on device
detach.

> diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
> index c6329d88d1c65..e52a0e2f55c2b 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");

[Severity: Medium]
Does devm_regulator_release() call regulator_put() on host->reg_va09 while
it is still enabled?

ufs_mtk_init() calls ufs_mtk_mphy_power_on(hba, true), which enables
host->reg_va09 via regulator_enable().  ufs_hba_mtk_vops does not implement
an .exit callback, and ufs_mtk_remove() -> ufshcd_pltfrm_remove() resumes
the device with pm_runtime_get_sync() without calling
ufs_mtk_mphy_power_on(hba, false).  When devres releases host->reg_va09 on
driver unbind or post-ufshcd_hba_init() probe failure, _regulator_put()
hits WARN_ON(regulator->enable_count) and leaks the regulator enable
reference.

[Severity: High]
This problem wasn't introduced by this patch, but in ufs_mtk_mphy_power_on()
[1], can a failed regulator_disable(host->reg_va09) leave
host->mphy_powered_on out of sync with the hardware?

drivers/ufs/host/ufs-mediatek.c:ufs_mtk_mphy_power_on() {
	if (!mphy || !(on ^ host->mphy_powered_on))
		return 0;

	if (on) {
		...
	} else {
		phy_power_off(mphy);
		if (ufs_mtk_is_va09_supported(hba)) {
			ufs_mtk_va09_pwr_ctrl(res, 0);
			ret = regulator_disable(host->reg_va09);
		}
	}
out:
	if (ret) {
		...
	} else {
		host->mphy_powered_on = on;
	}
}

When called with on = false, phy_power_off() powers down the M-PHY before
regulator_disable(host->reg_va09) runs.  If regulator_disable() returns an
error, host->mphy_powered_on remains true while the PHY is powered off, so
the next resume call with on = true hits !(on ^ host->mphy_powered_on) and
returns early without powering the PHY back on, causing subsequent I/O
timeouts and controller lockups.

[1] https://sashiko.dev/#/bug/linux-51b0f8e0-4730-46d4-afe5-42a3d31189f3

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118014234.424-1-laixiangwu@cmss.chinamobile.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-18  1:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18  1:42 [PATCH] scsi: ufs-mediatek: use devm_regulator_get() for the va09 regulator Xiangwu Lai
2026-11-18  1:54 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox