From 6efee14ca0aed33103ea17f4367da173f893442f Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Mon, 14 Sep 2026 16:49:24 +0800 Subject: scsi: ufs: core: Always notify POST_CHANGE even on gear switch failure 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 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 Reviewed-by: Chun-Hung Wu Link: https://patch.msgid.link/20260914085148.136429-2-peter.wang@mediatek.com Signed-off-by: Martin K. Petersen (Oracle) --- 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 1269185fc06a..fe8e35daa694 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -5020,8 +5020,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); -- cgit v1.2.3