diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 08cf9ab52..f0571854c 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -222,6 +222,8 @@ struct scst_cmd *scst_rx_cmd(struct scst_session *sess, goto out; cmd->sess = sess; + scst_sess_get(sess); + cmd->tgt = sess->tgt; cmd->tgtt = sess->tgt->tgtt; @@ -231,7 +233,6 @@ struct scst_cmd *scst_rx_cmd(struct scst_session *sess, SCST_LOAD_SENSE(scst_sense_lun_not_supported)); TRACE_DBG("cmd %p, sess %p", cmd, sess); - scst_sess_get(sess); out: TRACE_EXIT(); @@ -6036,6 +6037,10 @@ static struct scst_mgmt_cmd *scst_pre_rx_mgmt_cmd(struct scst_session } mcmd->sess = sess; + scst_sess_get(sess); + + atomic_inc(&sess->sess_cmd_count); + mcmd->fn = fn; mcmd->state = SCST_MCMD_STATE_INIT; mcmd->tgt_priv = tgt_priv; @@ -6058,8 +6063,6 @@ static int scst_post_rx_mgmt_cmd(struct scst_session *sess, TRACE_ENTRY(); - scst_sess_get(sess); - if (unlikely(sess->shut_phase != SCST_SESS_SPH_READY)) { PRINT_CRIT_ERROR("New mgmt cmd while shutting down the " "session %p shut_phase %ld", sess, sess->shut_phase); @@ -6069,7 +6072,6 @@ static int scst_post_rx_mgmt_cmd(struct scst_session *sess, local_irq_save(flags); spin_lock(&sess->sess_list_lock); - atomic_inc(&sess->sess_cmd_count); if (unlikely(sess->init_phase != SCST_SESS_IPH_READY)) { switch (sess->init_phase) {