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>

authored by Bart Van Assche and committed by Martin K. Petersen 14be351e 278712d2

+14 -11
+14 -11
drivers/ufs/core/ufshcd.c
··· 6699 6699 hba->saved_uic_err, hba->force_reset, 6700 6700 ufshcd_is_link_broken(hba) ? "; link is broken" : ""); 6701 6701 6702 - /* 6703 - * Use ufshcd_rpm_get_noresume() here to safely perform link recovery 6704 - * even if an error occurs during runtime suspend or runtime resume. 6705 - * This avoids potential deadlocks that could happen if we tried to 6706 - * resume the device while a PM operation is already in progress. 6707 - */ 6708 - ufshcd_rpm_get_noresume(hba); 6709 - if (hba->pm_op_in_progress) { 6710 - ufshcd_link_recovery(hba); 6702 + if (hba->ufs_device_wlun) { 6703 + /* 6704 + * Use ufshcd_rpm_get_noresume() here to safely perform link 6705 + * recovery even if an error occurs during runtime suspend or 6706 + * runtime resume. This avoids potential deadlocks that could 6707 + * happen if we tried to resume the device while a PM operation 6708 + * is already in progress. 6709 + */ 6710 + ufshcd_rpm_get_noresume(hba); 6711 + if (hba->pm_op_in_progress) { 6712 + ufshcd_link_recovery(hba); 6713 + ufshcd_rpm_put(hba); 6714 + return; 6715 + } 6711 6716 ufshcd_rpm_put(hba); 6712 - return; 6713 6717 } 6714 - ufshcd_rpm_put(hba); 6715 6718 6716 6719 down(&hba->host_sem); 6717 6720 spin_lock_irqsave(hba->host->host_lock, flags);