1
0
mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2026-01-11 17:10:13 +00:00

scsi: ufs: core: Fix an error handler crash

The UFS error handler may be activated before SCSI scanning has started
and hence before hba->ufs_device_wlun has been set. Check the
hba->ufs_device_wlun pointer before using it.

Cc: Peter Wang <peter.wang@mediatek.com>
Cc: Nitin Rawat <nitin.rawat@oss.qualcomm.com>
Fixes: e23ef4f22db3 ("scsi: ufs: core: Fix error handler host_sem issue")
Fixes: f966e02ae521 ("scsi: ufs: core: Fix runtime suspend error deadlock")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
Reviewed-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com>
Tested-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> #SM8750
Link: https://patch.msgid.link/20251204170457.994851-1-bvanassche@acm.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
Bart Van Assche 2025-12-04 07:04:52 -10:00 committed by Martin K. Petersen
parent 278712d20b
commit 14be351e5c

View File

@ -6699,19 +6699,22 @@ static void ufshcd_err_handler(struct work_struct *work)
hba->saved_uic_err, hba->force_reset,
ufshcd_is_link_broken(hba) ? "; link is broken" : "");
/*
* Use ufshcd_rpm_get_noresume() here to safely perform link recovery
* even if an error occurs during runtime suspend or runtime resume.
* This avoids potential deadlocks that could happen if we tried to
* resume the device while a PM operation is already in progress.
*/
ufshcd_rpm_get_noresume(hba);
if (hba->pm_op_in_progress) {
ufshcd_link_recovery(hba);
if (hba->ufs_device_wlun) {
/*
* Use ufshcd_rpm_get_noresume() here to safely perform link
* recovery even if an error occurs during runtime suspend or
* runtime resume. This avoids potential deadlocks that could
* happen if we tried to resume the device while a PM operation
* is already in progress.
*/
ufshcd_rpm_get_noresume(hba);
if (hba->pm_op_in_progress) {
ufshcd_link_recovery(hba);
ufshcd_rpm_put(hba);
return;
}
ufshcd_rpm_put(hba);
return;
}
ufshcd_rpm_put(hba);
down(&hba->host_sem);
spin_lock_irqsave(hba->host->host_lock, flags);