From bbbbbc3ae7a6692f9c0c3c7459aceb7aab3ad862 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 29 Mar 2022 13:45:23 -0700 Subject: [PATCH] FROMLIST: scsi: ufs: Move a clock scaling check Move a check related to clock scaling into ufshcd_devfreq_scale(). This patch prepares for adding a second ufshcd_clock_scaling_prepare() caller. Bug: 227177294 Link: https://lore.kernel.org/all/20220427233855.2685505-3-bvanassche@acm.org/ Change-Id: I928d4cbe64823960a6112ba7f98c18da6244a77c Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 6a810b956fbb..c8794045b14d 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1193,8 +1193,7 @@ static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba) ufshcd_scsi_block_requests(hba); down_write(&hba->clk_scaling_lock); - if (!hba->clk_scaling.is_allowed || - ufshcd_wait_for_doorbell_clr(hba, DOORBELL_CLR_TOUT_US)) { + if (ufshcd_wait_for_doorbell_clr(hba, DOORBELL_CLR_TOUT_US)) { ret = -EBUSY; up_write(&hba->clk_scaling_lock); ufshcd_scsi_unblock_requests(hba); @@ -1232,10 +1231,18 @@ static int ufshcd_devfreq_scale(struct ufs_hba *hba, bool scale_up) int ret = 0; bool is_writelock = true; + if (!hba->clk_scaling.is_allowed) + return -EBUSY; + ret = ufshcd_clock_scaling_prepare(hba); if (ret) return ret; + if (!hba->clk_scaling.is_allowed) { + ret = -EBUSY; + goto out_unprepare; + } + /* scale down the gear before scaling down clocks */ if (!scale_up) { ret = ufshcd_scale_gear(hba, false);