The branch main has been updated by jaeyoon:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=e59d4ec66fcab3da813f593f52bb8f1577cbb403

commit e59d4ec66fcab3da813f593f52bb8f1577cbb403
Author:     Jaeyoon Choi <[email protected]>
AuthorDate: 2026-08-27 05:03:02 +0000
Commit:     Jaeyoon Choi <[email protected]>
CommitDate: 2026-08-27 05:08:38 +0000

    ufshci: handle a recovery reset before the SIM attach
    
    When the first start attempt fails early, the recovery reset
    runs the start sequence again without a SIM. That pass still
    looked up the WLUN, so it dereferenced a NULL SIM and panicked.
    
    Attach the SIM whenever it does not exist yet. Also make the
    WLUN lookup return NULL when there is no SIM.
    
    Reviewed by:            imp (mentor)
    Sponsored by:           Samsung Electronics
    Differential Revision:  https://reviews.freebsd.org/D58947
---
 sys/dev/ufshci/ufshci_ctrlr.c | 7 ++++---
 sys/dev/ufshci/ufshci_sim.c   | 4 ++++
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/sys/dev/ufshci/ufshci_ctrlr.c b/sys/dev/ufshci/ufshci_ctrlr.c
index 2f930d55a295..69b6869e98e2 100644
--- a/sys/dev/ufshci/ufshci_ctrlr.c
+++ b/sys/dev/ufshci/ufshci_ctrlr.c
@@ -151,10 +151,11 @@ ufshci_ctrlr_start(struct ufshci_controller *ctrlr, bool 
resetting)
        /* TODO: Configure Background Operations */
 
        /*
-        * If the reset is due to a timeout, it is already attached to the SIM
-        * and does not need to be attached again.
+        * A reset normally arrives after the SIM is attached. But if the
+        * first start attempt failed early, the reset path runs without a
+        * SIM. Attach it whenever it does not exist yet.
         */
-       if (!resetting && ufshci_sim_attach(ctrlr) != 0) {
+       if (ctrlr->ufshci_sim == NULL && ufshci_sim_attach(ctrlr) != 0) {
                ufshci_ctrlr_fail(ctrlr);
                return;
        }
diff --git a/sys/dev/ufshci/ufshci_sim.c b/sys/dev/ufshci/ufshci_sim.c
index 2d9a425f6439..d9ea84961879 100644
--- a/sys/dev/ufshci/ufshci_sim.c
+++ b/sys/dev/ufshci/ufshci_sim.c
@@ -454,6 +454,10 @@ ufshci_sim_find_periph(struct ufshci_controller *ctrlr, 
uint8_t wlun)
        uint64_t scsi_lun;
        uint64_t timeout;
 
+       /* The reset path can get here before the SIM is attached. */
+       if (ctrlr->ufshci_sim == NULL)
+               return (NULL);
+
        scsi_lun = ufshci_sim_translate_ufs_to_scsi_lun(wlun);
 
        if (xpt_create_path(&path, /*periph*/ NULL,

Reply via email to