[PATCH 4/4] scsi: ufs: core: Make use of guard(mutex)

From: Avri Altman
Date: Tue Apr 16 2024 - 06:25:20 EST


Replace few lock/unlock instances.

Signed-off-by: Avri Altman <avri.altman@xxxxxxx>
---
drivers/ufs/core/ufshcd.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 3c62b69bbd52..c4b6b8276c20 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -4240,7 +4240,8 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd)
int ret;
bool reenable_intr = false;

- mutex_lock(&hba->uic_cmd_mutex);
+ guard(mutex)(&hba->uic_cmd_mutex);
+
ufshcd_add_delay_before_dme_cmd(hba);

scoped_guard(spinlock_irqsave, hba->host->host_lock) {
@@ -4310,8 +4311,6 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd)
}
}

- mutex_unlock(&hba->uic_cmd_mutex);
-
return ret;
}

@@ -5682,9 +5681,8 @@ int ufshcd_write_ee_control(struct ufs_hba *hba)
{
int err;

- mutex_lock(&hba->ee_ctrl_mutex);
+ guard(mutex)(&hba->ee_ctrl_mutex);
err = __ufshcd_write_ee_control(hba, hba->ee_ctrl_mask);
- mutex_unlock(&hba->ee_ctrl_mutex);
if (err)
dev_err(hba->dev, "%s: failed to write ee control %d\n",
__func__, err);
@@ -5697,7 +5695,7 @@ int ufshcd_update_ee_control(struct ufs_hba *hba, u16 *mask,
u16 new_mask, ee_ctrl_mask;
int err = 0;

- mutex_lock(&hba->ee_ctrl_mutex);
+ guard(mutex)(&hba->ee_ctrl_mutex);
new_mask = (*mask & ~clr) | set;
ee_ctrl_mask = new_mask | *other_mask;
if (ee_ctrl_mask != hba->ee_ctrl_mask)
@@ -5707,7 +5705,6 @@ int ufshcd_update_ee_control(struct ufs_hba *hba, u16 *mask,
hba->ee_ctrl_mask = ee_ctrl_mask;
*mask = new_mask;
}
- mutex_unlock(&hba->ee_ctrl_mutex);
return err;
}

@@ -6316,11 +6313,10 @@ static void ufshcd_force_error_recovery(struct ufs_hba *hba)

static void ufshcd_clk_scaling_allow(struct ufs_hba *hba, bool allow)
{
- mutex_lock(&hba->wb_mutex);
+ guard(mutex)(&hba->wb_mutex);
down_write(&hba->clk_scaling_lock);
hba->clk_scaling.is_allowed = allow;
up_write(&hba->clk_scaling_lock);
- mutex_unlock(&hba->wb_mutex);
}

static void ufshcd_clk_scaling_suspend(struct ufs_hba *hba, bool suspend)
--
2.42.0