From: <peter.wang@mediatek.com>
To: <linux-scsi@vger.kernel.org>, <martin.petersen@oracle.com>,
<avri.altman@sandisk.com>, <alim.akhtar@samsung.com>,
<bvanassche@acm.org>, <santosh.sy@samsung.com>,
<h.vinayak@samsung.com>
Cc: <wsd_upstream@mediatek.com>, <linux-mediatek@lists.infradead.org>,
<peter.wang@mediatek.com>, <chun-hung.wu@mediatek.com>,
<alice.chao@mediatek.com>, <cc.chou@mediatek.com>,
<chaotian.jing@mediatek.com>, <tun-yu.yu@mediatek.com>,
<naomi.chu@mediatek.com>, <ed.tsai@mediatek.com>
Subject: [PATCH v2 1/2] ufs: always notify POST_CHANGE even on gear switch failure
Date: Mon, 14 Sep 2026 16:49:24 +0800 [thread overview]
Message-ID: <20260914085148.136429-2-peter.wang@mediatek.com> (raw)
In-Reply-To: <20260914085148.136429-1-peter.wang@mediatek.com>
From: Peter Wang <peter.wang@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@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
next prev parent reply other threads:[~2026-09-14 8:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 8:49 [PATCH v2 0/2] ufs: fix POST_CHANGE pairing and AHIT race condition peter.wang
2026-09-14 8:49 ` peter.wang [this message]
2026-09-14 9:02 ` [PATCH v2 1/2] ufs: always notify POST_CHANGE even on gear switch failure sashiko-bot
2026-09-14 12:42 ` Peter Wang (王信友)
2026-09-14 8:49 ` [PATCH v2 2/2] ufs: serialize AHIT register access between sysfs and host driver peter.wang
2026-09-14 9:13 ` sashiko-bot
2026-09-14 12:44 ` Peter Wang (王信友)
2026-09-22 10:06 ` [PATCH v2 0/2] ufs: fix POST_CHANGE pairing and AHIT race condition chun-hung.wu
2026-09-26 2:30 ` Martin K. Petersen (Oracle)
2026-10-05 15:45 ` Sandeep Dhavale
2026-10-06 2:42 ` Martin K. Petersen
2026-10-06 2:44 ` Martin K. Petersen (Oracle)
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=20260914085148.136429-2-peter.wang@mediatek.com \
--to=peter.wang@mediatek.com \
--cc=alice.chao@mediatek.com \
--cc=alim.akhtar@samsung.com \
--cc=avri.altman@sandisk.com \
--cc=bvanassche@acm.org \
--cc=cc.chou@mediatek.com \
--cc=chaotian.jing@mediatek.com \
--cc=chun-hung.wu@mediatek.com \
--cc=ed.tsai@mediatek.com \
--cc=h.vinayak@samsung.com \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=naomi.chu@mediatek.com \
--cc=santosh.sy@samsung.com \
--cc=tun-yu.yu@mediatek.com \
--cc=wsd_upstream@mediatek.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox