[PATCH] scsi: ufs: mediatek: Handle mPHY power-on failures

From: Pengpeng Hou

Date: Fri Aug 28 2026 - 05:31:55 EST


ufs_mtk_mphy_power_on() enables the optional VA09 supply before powering
on the mPHY. The PHY result is ignored, so a failure leaves VA09
enabled and records mphy_powered_on as true, suppressing later retries.
The initialization path also ignores the helper result and continues
setting up the host.

Check phy_power_on(), turn VA09 back off on failure, and leave the state
flag unchanged. Propagate the helper error from initialization as well
as the existing resume caller. Keep regulator and mPHY diagnostics on
separate paths so regulator errors are not mislabeled.

The issue was identified via static analysis and manually reviewed.

Fixes: 561e3a8726b2 ("scsi: ufs-mediatek: Fix unbalanced clock on/off")
Fixes: cf137b3ea49a ("scsi: ufs-mediatek: Support VA09 regulator operations")

Assisted-by: LLM
Signed-off-by: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
---
drivers/ufs/host/ufs-mediatek.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
index 814c1b7343b9..9d481147ea38 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -509,6 +509,7 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on)
struct ufs_mtk_host *host = ufshcd_get_variant(hba);
struct phy *mphy = host->mphy;
struct arm_smccc_res res;
+ int rollback_ret;
int ret = 0;

if (!mphy || !(on ^ host->mphy_powered_on))
@@ -523,7 +524,18 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on)
usleep_range(200, 210);
ufs_mtk_va09_pwr_ctrl(res, 1);
}
- phy_power_on(mphy);
+ ret = phy_power_on(mphy);
+ if (ret) {
+ if (ufs_mtk_is_va09_supported(hba)) {
+ ufs_mtk_va09_pwr_ctrl(res, 0);
+ rollback_ret = regulator_disable(host->reg_va09);
+ if (rollback_ret)
+ dev_warn(hba->dev, "failed to disable va09 after mphy failure: %d\n",
+ rollback_ret);
+ }
+ dev_info(hba->dev, "failed to enable mphy: %d\n", ret);
+ return ret;
+ }
} else {
phy_power_off(mphy);
if (ufs_mtk_is_va09_supported(hba)) {
@@ -1295,7 +1307,9 @@ static int ufs_mtk_init(struct ufs_hba *hba)
*
* Enable phy clocks specifically here.
*/
- ufs_mtk_mphy_power_on(hba, true);
+ err = ufs_mtk_mphy_power_on(hba, true);
+ if (err)
+ goto out_variant_clear;

if (ufs_mtk_is_rtff_mtcmos(hba)) {
/* First Restore here, to avoid backup unexpected value */
--
2.43.0