scsi: ufs: mediatek: handle mPHY power-on failures
PATCH v2 1/1 scsi: ufs: mediatek: handle mPHY power-on failures
The MediaTek helper enables VA09 before powering on the mPHY, but ignores the PHY result. A failure can leave VA09 enabled and publish mphy_powered_on as true, so a later power-on attempt is skipped.
Check phy_power_on(), attempt to unwind VA09 on failure, and leave the state flag unchanged. Propagate the helper result from host initialization as well as its existing resume caller. Keep the original PHY error if the supply rollback also fails, and report that rollback separately.
The issue was found by our static-analysis tool.
---
Changes since v1:
https://lore.kernel.org/all/[email protected]/
Use err for the rollback result and dev_err() for operation failures, as Stanley requested.
drivers/ufs/host/ufs-mediatek.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/ufs/host/ufs-mediatek.c +16 -2
@@ -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 err;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 ); + err =regulator_disable (host->reg_va09); +if (err) +dev_err (hba->dev, +"failed to unwind va09: %d\n" , err); + } +dev_err (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 */
base-commit: 518e5b794c06c0f0eb40df3e202274a66202c137
Signature · 1 line
2.50.1 (Apple Git-155)
Quoted 14 lines · Pengpeng Hou
The MediaTek helper enables VA09 before powering on the mPHY, but ignores the PHY result. A failure can leave VA09 enabled and publish
mphy_powered_onas true, so a later power-on attempt is skipped.Check
phy_power_on(), attempt to unwind VA09 on failure, and leave the
state flag unchanged. Propagate the helper result from host initialization as well as its existing resume caller. Keep the original
PHY error if the supply rollback also fails, and report that rollback separately.The issue was found by our static-analysis tool.
Quoted 7 lines
Fixes 561e3a8726b2 ("scsi: ufs-mediatek: Fix unbalanced clockon/off")
Fixes cf137b3ea49a ("scsi: ufs-mediatek: Support VA09 regulatoroperations")
Assisted-by gpt 5Signed-off-by Pengpeng Hou <[email protected]>---
Quoted 5 lines · Pengpeng Hou
Check
phy_power_on(), attempt to unwind VA09 on failure, and leave the state flag unchanged. Propagate the helper result from host initialization as well as its existing resume caller. Keep the original PHY error if the supply rollback also fails, and report that rollback separately.
Quoted 11 lines · Pengpeng Hou
The MediaTek helper enables VA09 before powering on the mPHY, but ignores the PHY result. A failure can leave VA09 enabled and publish
mphy_powered_onas true, so a later power-on attempt is skipped.Check
phy_power_on(), attempt to unwind VA09 on failure, and leave the state flag unchanged. Propagate the helper result from host initialization as well as its existing resume caller. Keep the original PHY error if the supply rollback also fails, and report that rollback separately.[...]
Applied to 7.3/scsi-fixes, thanks!
[1/1] scsi: ufs: mediatek: handle mPHY power-on failures
https://git.kernel.org/mkp/scsi/c/78e04810542d
Signature · 1 line
Martin K. Petersen