[PATCH v10 20/26] scsi: ufs: mediatek: Back up idle timer in per-instance struct
Louis-Alexis Eyraud <[email protected]> Thu, 30 Jul 2026 11:49:16 +0200
| Newsgroups | org.infradead.lists.linux-mediatek,org.infradead.lists.linux-arm-kernel,org.infradead.lists.linux-phy,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-kernel,org.kernel.vger.linux-scsi |
|---|---|
| Message-ID | <[email protected]> |
From: Nicolas Frattaroli <[email protected]> The MediaTek UFS driver uses a function-scope static variable to back up a hardware register across a power change in the ufs_mtk_pwr_change_notify function. This is dangerous, as it's only correct if only ever one instance of the driver is loaded, which isn't true if there's more than one device on a SoC that needs it, or it otherwise gets loaded a second time. Back it up into a member of the host struct instead, as this struct is per-instance. Rework the function to not use a pointless "ret" local as well. Fixes: f5ca8d0c7a63 ("scsi: ufs: host: mediatek: Disable auto-hibern8 during power mode changes") Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Signed-off-by: Nicolas Frattaroli <[email protected]> Reviewed-by: Chaotian Jing <[email protected]> Signed-off-by: Louis-Alexis Eyraud <[email protected]> --- drivers/ufs/host/ufs-mediatek.c | 19 ++++++++----------- drivers/ufs/host/ufs-mediatek.h | 1 + 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c index c784ecb30e74..115056927223 100644 --- a/drivers/ufs/host/ufs-mediatek.c +++ b/drivers/ufs/host/ufs-mediatek.c @@ -1400,27 +1400,24 @@ static int ufs_mtk_pwr_change_notify(struct ufs_hba *hba, enum ufs_notify_change_status stage, struct ufs_pa_layer_attr *dev_req_params) { - int ret = 0; - static u32 reg; + struct ufs_mtk_host *host = ufshcd_get_variant(hba); switch (stage) { case PRE_CHANGE: if (ufshcd_is_auto_hibern8_supported(hba)) { - reg = ufshcd_readl(hba, REG_AUTO_HIBERNATE_IDLE_TIMER); + host->ahit = ufshcd_readl( + hba, REG_AUTO_HIBERNATE_IDLE_TIMER); ufs_mtk_auto_hibern8_disable(hba); } - ret = ufs_mtk_pre_pwr_change(hba, dev_req_params); - break; + return ufs_mtk_pre_pwr_change(hba, dev_req_params); case POST_CHANGE: if (ufshcd_is_auto_hibern8_supported(hba)) - ufshcd_writel(hba, reg, REG_AUTO_HIBERNATE_IDLE_TIMER); - break; - default: - ret = -EINVAL; - break; + ufshcd_writel(hba, host->ahit, + REG_AUTO_HIBERNATE_IDLE_TIMER); + return 0; } - return ret; + return -EINVAL; } static int ufs_mtk_unipro_set_lpm(struct ufs_hba *hba, bool lpm) diff --git a/drivers/ufs/host/ufs-mediatek.h b/drivers/ufs/host/ufs-mediatek.h index 634c76c903c0..7f2cdfd632be 100644 --- a/drivers/ufs/host/ufs-mediatek.h +++ b/drivers/ufs/host/ufs-mediatek.h @@ -187,6 +187,7 @@ struct ufs_mtk_host { u16 ref_clk_gating_wait_us; u32 ip_ver; bool legacy_ip_ver; + u32 ahit; bool mcq_set_intr; bool is_mcq_intr_enabled; -- 2.55.0