- Fixed a race, which could lead to BUG() in scst_mgmt_thread()
[mirror/scst/.git] / scst / src / scst_targ.c
index 6cdbff8..0e5c416 100644 (file)
@@ -3861,11 +3861,13 @@ restart:
                list_for_each_entry(sess, &scst_sess_mgmt_list,
                        sess_mgmt_list_entry)
                {
+                       int shutting_down;
                        TRACE_DBG("Removing sess %p from scst_sess_mgmt_list",
                                sess);
                        list_del(&sess->sess_mgmt_list_entry);
+                       shutting_down = sess->shutting_down;
                        spin_unlock_irq(&scst_mgmt_lock);
-                       if (sess->shutting_down) {
+                       if (shutting_down) {
                                BUG_ON(atomic_read(&sess->refcnt) != 0);
                                scst_free_session_callback(sess);
                        } else if (sess->init_phase == SCST_SESS_IPH_INITING) {