/* Must be called with session lock. This function returns the scsi command to scsi-ml or cleans up mgmt tasks then returns the task to the pool.  */
static void iscsi_free_task(struct iscsi_task *task)
/* Must be called with session lock. This function returns the scsi command to scsi-ml or cleans up mgmt tasks then returns the task to the pool.  */
static void iscsi_free_task(struct iscsi_task *task)
{
	struct iscsi_conn *conn = task->conn;
	struct iscsi_session *session = conn->session;
	struct scsi_cmnd *sc = task->sc;
	ISCSI_DBG_SESSION(session, "freeing task itt 0x%x state %d sc %p\n",
			  task->itt, task->state, task->sc);
	session->tt->cleanup_task(task);
	task->state = ISCSI_TASK_FREE;
	task->sc = NULL;
	if (conn->login_task == task)
		return;
	kfifo_in(&session->cmdpool.queue, (void*)&task, sizeof(void*));
	if (sc) {
		task->sc = NULL;
		sc->SCp.ptr = NULL;
		if (sc->scsi_done)
			sc->scsi_done(sc);
	}
}