Skip to content

Commit 61f3616

Browse files
author
Nicholas Bellinger
committed
Revert "target: Fix residual overflow handling in target_complete_cmd_with_length"
This reverts commit c1ccbfe. Reverting this patch, as it incorrectly assumes the additional length for INQUIRY in target_complete_cmd_with_length() is SCSI allocation length, which breaks existing user-space code when SCSI allocation length is smaller than additional length. root@scsi-mq:~# sg_inq --len=4 -vvvv /dev/sdb found bsg_major=253 open /dev/sdb with flags=0x800 inquiry cdb: 12 00 00 00 04 00 duration=0 ms inquiry: pass-through requested 4 bytes (data-in) but got -28 bytes inquiry: pass-through can't get negative bytes, say it got none inquiry: got too few bytes (0) INQUIRY resid (32) should never exceed requested len=4 inquiry: failed requesting 4 byte response: Malformed response to SCSI command [resid=32] AFAICT the original change was not to address a specific host issue, so go ahead and revert to original logic for now. Cc: Douglas Gilbert <dgilbert@interlog.com> Cc: Martin K. Petersen <martin.petersen@oracle.com> Cc: Sumit Rai <sumitrai96@gmail.com> Cc: stable@vger.kernel.org # 4.8+ Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent 926317d commit 61f3616

1 file changed

Lines changed: 1 addition & 15 deletions

File tree

drivers/target/target_core_transport.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -754,15 +754,7 @@ EXPORT_SYMBOL(target_complete_cmd);
754754

755755
void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int length)
756756
{
757-
if (scsi_status != SAM_STAT_GOOD) {
758-
return;
759-
}
760-
761-
/*
762-
* Calculate new residual count based upon length of SCSI data
763-
* transferred.
764-
*/
765-
if (length < cmd->data_length) {
757+
if (scsi_status == SAM_STAT_GOOD && length < cmd->data_length) {
766758
if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) {
767759
cmd->residual_count += cmd->data_length - length;
768760
} else {
@@ -771,12 +763,6 @@ void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int len
771763
}
772764

773765
cmd->data_length = length;
774-
} else if (length > cmd->data_length) {
775-
cmd->se_cmd_flags |= SCF_OVERFLOW_BIT;
776-
cmd->residual_count = length - cmd->data_length;
777-
} else {
778-
cmd->se_cmd_flags &= ~(SCF_OVERFLOW_BIT | SCF_UNDERFLOW_BIT);
779-
cmd->residual_count = 0;
780766
}
781767

782768
target_complete_cmd(cmd, scsi_status);

0 commit comments

Comments
 (0)