]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
scsi: ufs: core: Fix an error handler crash
authorBart Van Assche <bvanassche@acm.org>
Thu, 4 Dec 2025 17:04:52 +0000 (07:04 -1000)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 9 Dec 2025 02:56:33 +0000 (21:56 -0500)
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>
drivers/ufs/core/ufshcd.c

index 1b3fe1d8655e6dfa67b4086811317832bc236fbe..1837ae204d5eb0b42d7358583dc2d4450d261cf7 100644 (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);