From 80d85e5d973d9ee3ae0cc44580f78c37d8e83c27 Mon Sep 17 00:00:00 2001 From: Can Guo Date: Thu, 30 Jul 2020 20:44:55 +0800 Subject: [PATCH] scsi: ufs: Make sure clk scaling happens only when hba is runtime ACTIVE If someone plays with the UFS clk scaling devfreq governor through sysfs, ufshcd_devfreq_scale may be called even when hba is not runtime ACTIVE, which can lead to unexpected error. We cannot just protect it by calling pm_runtime_get_sync, because that may cause racing problem since hba runtime suspend ops needs to suspend clk scaling. In order to fix it, call pm_runtime_get_noresume and check hba's runtime status, then only proceed if hba is runtime ACTIVE, otherwise just bail. governor_store devfreq_performance_handler update_devfreq devfreq_set_target ufshcd_devfreq_target ufshcd_devfreq_scale Change-Id: I1345985d50bcb239b7af008f7d295de3d7581112 Signed-off-by: Can Guo --- drivers/scsi/ufs/ufshcd.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 42c6d6cd0b56..7d3c2fb9d634 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1357,8 +1357,19 @@ static int ufshcd_devfreq_target(struct device *dev, } spin_unlock_irqrestore(hba->host->host_lock, irq_flags); +#if defined(CONFIG_SCSI_UFSHCD_QTI) + pm_runtime_get_noresume(hba->dev); + if (!pm_runtime_active(hba->dev)) { + pm_runtime_put_noidle(hba->dev); + ret = -EAGAIN; + goto out; + } +#endif start = ktime_get(); ret = ufshcd_devfreq_scale(hba, scale_up); +#if defined(CONFIG_SCSI_UFSHCD_QTI) + pm_runtime_put(hba->dev); +#endif trace_ufshcd_profile_clk_scaling(dev_name(hba->dev), (scale_up ? "up" : "down"),