diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index fb7467eef..f5b56fd5b 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -132,7 +132,7 @@ void scst_set_resp_data_len(struct scst_cmd *cmd, int resp_data_len) cmd->orig_sg_cnt = cmd->sg_cnt; cmd->orig_sg_entry = i; cmd->orig_entry_len = cmd->sg[i].length; - cmd->sg_cnt = i+1; + cmd->sg_cnt = (left > 0) ? i+1 : i; cmd->sg[i].length = left; cmd->sg_buff_modified = 1; break; diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 9752ae16d..0e320aeb0 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -1140,7 +1140,7 @@ static void scst_do_cmd_done(struct scst_cmd *cmd, int result, cmd->driver_status = driver_byte(result); if (unlikely(resid != 0)) { #ifdef EXTRACHECKS - if ((resid < 0) || (resid >= cmd->resp_data_len)) { + if ((resid < 0) || (resid > cmd->resp_data_len)) { PRINT_ERROR_PR("Wrong resid %d (cmd->resp_data_len=%d)", resid, cmd->resp_data_len); } else