Skip to content

Commit 73cc291

Browse files
Can Guomartinkpetersen
authored andcommitted
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. This can lead to unexpected error. We cannot just protect it by calling pm_runtime_get_sync() because that may cause a race condition since HBA runtime suspend ops need to suspend clk scaling. To fix this call pm_runtime_get_noresume() and check HBA's runtime status. 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 Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Stanley Chu <[email protected]> Signed-off-by: Can Guo <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 1699f98 commit 73cc291

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/scsi/ufs/ufshcd.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,15 @@ static int ufshcd_devfreq_target(struct device *dev,
12941294
}
12951295
spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
12961296

1297+
pm_runtime_get_noresume(hba->dev);
1298+
if (!pm_runtime_active(hba->dev)) {
1299+
pm_runtime_put_noidle(hba->dev);
1300+
ret = -EAGAIN;
1301+
goto out;
1302+
}
12971303
start = ktime_get();
12981304
ret = ufshcd_devfreq_scale(hba, scale_up);
1305+
pm_runtime_put(hba->dev);
12991306

13001307
trace_ufshcd_profile_clk_scaling(dev_name(hba->dev),
13011308
(scale_up ? "up" : "down"),

0 commit comments

Comments
 (0)