Skip to content

Commit e23ef4f

Browse files
ptr324martinkpetersen
authored andcommitted
scsi: ufs: core: Fix error handler host_sem issue
Fix the issue where host_sem is not released due to a new return path in commit f966e02 ("scsi: ufs: core: Fix runtime suspend error deadlock"). Check pm_op_in_progress before acquiring hba->host_sem to prevent deadlocks and ensure proper resource management during error handling. Add comment for use ufshcd_rpm_get_noresume() to safely perform link recovery without interfering with ongoing PM operations. Fixes: f966e02 ("scsi: ufs: core: Fix runtime suspend error deadlock") Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Peter Wang <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent a0b7780 commit e23ef4f

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

drivers/ufs/core/ufshcd.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6673,6 +6673,20 @@ static void ufshcd_err_handler(struct work_struct *work)
66736673
hba->saved_uic_err, hba->force_reset,
66746674
ufshcd_is_link_broken(hba) ? "; link is broken" : "");
66756675

6676+
/*
6677+
* Use ufshcd_rpm_get_noresume() here to safely perform link recovery
6678+
* even if an error occurs during runtime suspend or runtime resume.
6679+
* This avoids potential deadlocks that could happen if we tried to
6680+
* resume the device while a PM operation is already in progress.
6681+
*/
6682+
ufshcd_rpm_get_noresume(hba);
6683+
if (hba->pm_op_in_progress) {
6684+
ufshcd_link_recovery(hba);
6685+
ufshcd_rpm_put(hba);
6686+
return;
6687+
}
6688+
ufshcd_rpm_put(hba);
6689+
66766690
down(&hba->host_sem);
66776691
spin_lock_irqsave(hba->host->host_lock, flags);
66786692
if (ufshcd_err_handling_should_stop(hba)) {
@@ -6684,14 +6698,6 @@ static void ufshcd_err_handler(struct work_struct *work)
66846698
}
66856699
spin_unlock_irqrestore(hba->host->host_lock, flags);
66866700

6687-
ufshcd_rpm_get_noresume(hba);
6688-
if (hba->pm_op_in_progress) {
6689-
ufshcd_link_recovery(hba);
6690-
ufshcd_rpm_put(hba);
6691-
return;
6692-
}
6693-
ufshcd_rpm_put(hba);
6694-
66956701
ufshcd_err_handling_prepare(hba);
66966702

66976703
spin_lock_irqsave(hba->host->host_lock, flags);

0 commit comments

Comments
 (0)