diff --git a/sys/dev/amr/amr_cam.c b/sys/dev/amr/amr_cam.c index 17cd8356f7f1..3c7aaf889dec 100644 --- a/sys/dev/amr/amr_cam.c +++ b/sys/dev/amr/amr_cam.c @@ -139,10 +139,12 @@ amr_cam_attach(struct amr_softc *sc) /* * Allocate a devq for all our channels combined. This should * allow for the maximum number of SCSI commands we will accept - * at one time. + * at one time. Save the pointer in the softc so we can find it later + * during detach. */ if ((devq = cam_simq_alloc(AMR_MAX_SCSI_CMDS)) == NULL) return(ENOMEM); + sc->amr_cam_devq = devq; /* * Iterate over our channels, registering them with CAM @@ -182,19 +184,22 @@ amr_cam_attach(struct amr_softc *sc) void amr_cam_detach(struct amr_softc *sc) { - int chn, first; + int chn; - for (chn = 0, first = 1; chn < sc->amr_maxchan; chn++) { + for (chn = 0; chn < sc->amr_maxchan; chn++) { /* * If a sim was allocated for this channel, free it */ if (sc->amr_cam_sim[chn] != NULL) { xpt_bus_deregister(cam_sim_path(sc->amr_cam_sim[chn])); - cam_sim_free(sc->amr_cam_sim[chn], first ? TRUE : FALSE); - first = 0; + cam_sim_free(sc->amr_cam_sim[chn], FALSE); } } + + /* Now free the devq */ + if (sc->amr_cam_devq != NULL) + cam_simq_free(sc->amr_cam_devq); } /******************************************************************************** diff --git a/sys/dev/amr/amrvar.h b/sys/dev/amr/amrvar.h index ee0a27ca552c..6dc68387da8e 100644 --- a/sys/dev/amr/amrvar.h +++ b/sys/dev/amr/amrvar.h @@ -202,6 +202,7 @@ struct amr_softc /* CAM attachments for passthrough */ struct cam_sim *amr_cam_sim[AMR_MAX_CHANNELS]; TAILQ_HEAD(, ccb_hdr) amr_cam_ccbq; + struct cam_devq *amr_cam_devq; /* control device */ struct cdev *amr_dev_t;