From db629f0c2f66769f40c6cb80a1133f57f9dd26ae Mon Sep 17 00:00:00 2001 From: scottl Date: Wed, 2 May 2007 04:44:31 +0000 Subject: Streamline locking in ciss_free() --- sys/dev/ciss/ciss.c | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/ciss/ciss.c b/sys/dev/ciss/ciss.c index b19086f..153ab97 100644 --- a/sys/dev/ciss/ciss.c +++ b/sys/dev/ciss/ciss.c @@ -1665,19 +1665,42 @@ ciss_free(struct ciss_softc *sc) sc->ciss_flags |= CISS_FLAG_ABORTING; /* terminate the periodic heartbeat routine */ - mtx_unlock(&sc->ciss_mtx); - callout_drain(&sc->ciss_periodic); - mtx_lock(&sc->ciss_mtx); + callout_stop(&sc->ciss_periodic); /* cancel the Event Notify chain */ ciss_notify_abort(sc); ciss_kill_notify_thread(sc); + /* disconnect from CAM */ + if (sc->ciss_cam_sim) { + for (i = 0; i < sc->ciss_max_logical_bus; i++) { + if (sc->ciss_cam_sim[i]) { + xpt_bus_deregister(cam_sim_path(sc->ciss_cam_sim[i])); + cam_sim_free(sc->ciss_cam_sim[i], 0); + } + } + for (i = CISS_PHYSICAL_BASE; i < sc->ciss_max_physical_bus + + CISS_PHYSICAL_BASE; i++) { + if (sc->ciss_cam_sim[i]) { + xpt_bus_deregister(cam_sim_path(sc->ciss_cam_sim[i])); + cam_sim_free(sc->ciss_cam_sim[i], 0); + } + } + free(sc->ciss_cam_sim, CISS_MALLOC_CLASS); + } + if (sc->ciss_cam_devq) + cam_simq_free(sc->ciss_cam_devq); + /* remove the control device */ + mtx_unlock(&sc->ciss_mtx); if (sc->ciss_dev_t != NULL) destroy_dev(sc->ciss_dev_t); + /* Final cleanup of the callout. */ + callout_drain(&sc->ciss_periodic); + mtx_destroy(&sc->ciss_mtx); + /* free the controller data */ if (sc->ciss_id != NULL) free(sc->ciss_id, CISS_MALLOC_CLASS); @@ -1712,27 +1735,6 @@ ciss_free(struct ciss_softc *sc) if (sc->ciss_command_dmat) bus_dma_tag_destroy(sc->ciss_command_dmat); - /* disconnect from CAM */ - if (sc->ciss_cam_sim) { - for (i = 0; i < sc->ciss_max_logical_bus; i++) { - if (sc->ciss_cam_sim[i]) { - xpt_bus_deregister(cam_sim_path(sc->ciss_cam_sim[i])); - cam_sim_free(sc->ciss_cam_sim[i], 0); - } - } - for (i = CISS_PHYSICAL_BASE; i < sc->ciss_max_physical_bus + - CISS_PHYSICAL_BASE; i++) { - if (sc->ciss_cam_sim[i]) { - xpt_bus_deregister(cam_sim_path(sc->ciss_cam_sim[i])); - cam_sim_free(sc->ciss_cam_sim[i], 0); - } - } - free(sc->ciss_cam_sim, CISS_MALLOC_CLASS); - } - if (sc->ciss_cam_devq) - cam_simq_free(sc->ciss_cam_devq); - mtx_destroy(&sc->ciss_mtx); - if (sc->ciss_logical) { for (i = 0; i <= sc->ciss_max_logical_bus; i++) { for (j = 0; j < CISS_MAX_LOGICAL; j++) { @@ -3097,8 +3099,7 @@ ciss_periodic(void *arg) /* * Reschedule. */ - if (!(sc->ciss_flags & CISS_FLAG_ABORTING)) - callout_reset(&sc->ciss_periodic, CISS_HEARTBEAT_RATE * hz, ciss_periodic, sc); + callout_reset(&sc->ciss_periodic, CISS_HEARTBEAT_RATE * hz, ciss_periodic, sc); } /************************************************************************ -- cgit v1.1