return 0;
 }
 
-static int tcm_loop_queue_data_in(struct se_cmd *se_cmd)
+static int tcm_loop_queue_data_or_status(const char *func,
+               struct se_cmd *se_cmd, u8 scsi_status)
 {
        struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
                                struct tcm_loop_cmd, tl_se_cmd);
        struct scsi_cmnd *sc = tl_cmd->sc;
 
        pr_debug("%s() called for scsi_cmnd: %p cdb: 0x%02x\n",
-                __func__, sc, sc->cmnd[0]);
-
-       sc->result = SAM_STAT_GOOD;
-       set_host_byte(sc, DID_OK);
-       if ((se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) ||
-           (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT))
-               scsi_set_resid(sc, se_cmd->residual_count);
-       sc->scsi_done(sc);
-       return 0;
-}
-
-static int tcm_loop_queue_status(struct se_cmd *se_cmd)
-{
-       struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
-                               struct tcm_loop_cmd, tl_se_cmd);
-       struct scsi_cmnd *sc = tl_cmd->sc;
-
-       pr_debug("%s() called for scsi_cmnd: %p cdb: 0x%02x\n",
-                __func__, sc, sc->cmnd[0]);
+                func, sc, sc->cmnd[0]);
 
        if (se_cmd->sense_buffer &&
           ((se_cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) ||
                sc->result = SAM_STAT_CHECK_CONDITION;
                set_driver_byte(sc, DRIVER_SENSE);
        } else
-               sc->result = se_cmd->scsi_status;
+               sc->result = scsi_status;
 
        set_host_byte(sc, DID_OK);
        if ((se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) ||
        return 0;
 }
 
+static int tcm_loop_queue_data_in(struct se_cmd *se_cmd)
+{
+       return tcm_loop_queue_data_or_status(__func__, se_cmd, SAM_STAT_GOOD);
+}
+
+static int tcm_loop_queue_status(struct se_cmd *se_cmd)
+{
+       return tcm_loop_queue_data_or_status(__func__,
+                                            se_cmd, se_cmd->scsi_status);
+}
+
 static void tcm_loop_queue_tm_rsp(struct se_cmd *se_cmd)
 {
        struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,