All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xiangwu Lai" <laixiangwu@cmss.chinamobile.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: ufs-mediatek: use devm_regulator_get() for the va09 regulator
Date: Wed, 18 Nov 2026 01:54:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-219916@kernel.org> (raw)
In-Reply-To: <20261118014234.424-1-laixiangwu@cmss.chinamobile.com>

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

  reply	other threads:[~2026-11-18  1:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]
2026-11-18  3:20   ` Xiangwu Lai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-219916@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=laixiangwu@cmss.chinamobile.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.