[PATCH v2 1/2] ufs: always notify POST_CHANGE even on gear switch failure
peter.wang at mediatek.com
peter.wang at mediatek.com
Mon Sep 14 01:49:24 PDT 2026
From: Peter Wang <peter.wang at mediatek.com>
Previously, POST_CHANGE was only notified on a successful gear switch.
This could leave the host in an inconsistent state if resources were
acquired in PRE_CHANGE (e.g. disabling auto-hibern8) but never
released due to a missing POST_CHANGE.
Fix this by always calling POST_CHANGE regardless of the gear switch
result. On failure, pass dev_req_params = NULL to signal that there is
nothing to apply; hosts that receive NULL simply skip their post work.
Update the affected vendor drivers (ufs-exynos and ufshcd-pci) to
guard their POST_CHANGE logic with a NULL check so they correctly
handle the failure case.
Fixes: f5ca8d0c7a63 ("scsi: ufs: host: mediatek: Disable auto-hibern8 during power mode changes")
Signed-off-by: Peter Wang <peter.wang at mediatek.com>
---
drivers/ufs/core/ufshcd.c | 8 ++++++--
drivers/ufs/host/ufs-exynos.c | 4 +++-
drivers/ufs/host/ufshcd-pci.c | 3 ++-
3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 2ba244cf40ac..39a4bdafc1af 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -4979,8 +4979,12 @@ int ufshcd_change_power_mode(struct ufs_hba *hba,
ret = ufshcd_dme_change_power_mode(hba, pwr_mode, pmc_policy);
- if (!ret)
- ufshcd_vops_pwr_change_notify(hba, POST_CHANGE, pwr_mode);
+ /*
+ * Always notify POST_CHANGE to pair with PRE_CHANGE, even on failure.
+ * On failure, pass dev_req_params = NULL to indicate nothing to apply.
+ * POST_CHANGE return value is advisory and does not mask @ret.
+ */
+ ufshcd_vops_pwr_change_notify(hba, POST_CHANGE, ret ? NULL : pwr_mode);
return ret;
}
diff --git a/drivers/ufs/host/ufs-exynos.c b/drivers/ufs/host/ufs-exynos.c
index b2f65c465525..3bcbc9ebbb28 100644
--- a/drivers/ufs/host/ufs-exynos.c
+++ b/drivers/ufs/host/ufs-exynos.c
@@ -1782,7 +1782,9 @@ static int exynos_ufs_pwr_change_notify(struct ufs_hba *hba,
ret = exynos_ufs_pre_pwr_mode(hba, dev_req_params);
break;
case POST_CHANGE:
- ret = exynos_ufs_post_pwr_mode(hba, dev_req_params);
+ /* NULL when the gear switch failed: nothing to apply */
+ if (dev_req_params)
+ ret = exynos_ufs_post_pwr_mode(hba, dev_req_params);
break;
}
diff --git a/drivers/ufs/host/ufshcd-pci.c b/drivers/ufs/host/ufshcd-pci.c
index 21bb11c724be..668b57403e62 100644
--- a/drivers/ufs/host/ufshcd-pci.c
+++ b/drivers/ufs/host/ufshcd-pci.c
@@ -166,7 +166,8 @@ static int ufs_intel_lkf_pwr_change_notify(struct ufs_hba *hba,
ufs_intel_set_lanes(hba, 2);
break;
case POST_CHANGE:
- if (ufshcd_is_hs_mode(dev_req_params)) {
+ /* NULL when the gear switch failed: nothing to apply */
+ if (dev_req_params && ufshcd_is_hs_mode(dev_req_params)) {
u32 peer_granularity;
usleep_range(1000, 1250);
--
2.45.2
More information about the Linux-mediatek
mailing list