Index: sys/cam/cam_xpt.c =================================================================== --- sys/cam/cam_xpt.c +++ sys/cam/cam_xpt.c @@ -5377,8 +5377,8 @@ static void xpt_done_process(struct ccb_hdr *ccb_h) { - struct cam_sim *sim; - struct cam_devq *devq; + struct cam_sim *sim = NULL; + struct cam_devq *devq = NULL; struct mtx *mtx = NULL; #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING) @@ -5421,9 +5421,15 @@ mtx_unlock(&xsoftc.xpt_highpower_lock); } - sim = ccb_h->path->bus->sim; + /* + * Insulate against a race where the periph is destroyed + * but CCBs are still not all processed. + */ + if (ccb_h->path->bus) + sim = ccb_h->path->bus->sim; if (ccb_h->status & CAM_RELEASE_SIMQ) { + KASSERT(sim, "sim missing for CAM_RELEASE_SIMQ request"); xpt_release_simq(sim, /*run_queue*/FALSE); ccb_h->status &= ~CAM_RELEASE_SIMQ; } @@ -5434,10 +5440,13 @@ ccb_h->status &= ~CAM_DEV_QFRZN; } - devq = sim->devq; if ((ccb_h->func_code & XPT_FC_USER_CCB) == 0) { struct cam_ed *dev = ccb_h->path->device; + if (sim) + devq = sim->devq; + KASSERT(devq, "sim missing for XPT_FC_USER_CCB request"); + mtx_lock(&devq->send_mtx); devq->send_active--; devq->send_openings++;