--- bt.c +++ bt.c @@ -786,6 +786,17 @@ /* * Setup interrupt. */ error = bus_setup_intr(dev, bt->irq, INTR_MPSAFE, bt_intr, bt, &bt->ih, NULL); if (error) { device_printf(dev, "bus_setup_intr() failed: %d\n", error); + /* + * Tear down the CAM state registered above. The PCI + * glue releases our port/IRQ resources and DMA memory + * on attach failure; the XPT must not keep a bus whose + * sim action closure points at the freed softc. + */ + lockmgr(&bt->lock, LK_EXCLUSIVE); + xpt_free_path(bt->path); + bt->path = NULL; + xpt_bus_deregister(cam_sim_path(bt->sim)); + cam_sim_free(bt->sim); + bt->sim = NULL; + lockmgr(&bt->lock, LK_RELEASE); return (error); } return (0);