Skip to content

Commit b3127a7

Browse files
damien-lemoalopsiff
authored andcommitted
ata: libata-scsi: Return aborted command when missing sense and result TF
Commit d2be9ea9a75550a35c5127a6c2633658bc38c76b upstream. ata_gen_ata_sense() is always called for a failed qc missing sense data so that a sense key, code and code qualifier can be generated using ata_to_sense_error() from the qc status and error fields of its result task file. However, if the qc does not have its result task file filled, ata_gen_ata_sense() returns early without setting a sense key. Improve this by defaulting to returning ABORTED COMMAND without any additional sense code, since we do not know the reason for the failure. The same fix is also applied in ata_gen_passthru_sense() with the additional check that the qc failed (qc->err_mask is set). Fixes: 816be86 ("ata: libata-scsi: Check ATA_QCFLAG_RTF_FILLED before using result_tf") Cc: [email protected] Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 5b7912d83962085d087f030a9a465d138275a481)
1 parent 5480b93 commit b3127a7

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

drivers/ata/libata-scsi.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,8 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
935935
if (!(qc->flags & ATA_QCFLAG_RTF_FILLED)) {
936936
ata_dev_dbg(dev,
937937
"missing result TF: can't generate ATA PT sense data\n");
938+
if (qc->err_mask)
939+
ata_scsi_set_sense(dev, cmd, ABORTED_COMMAND, 0, 0);
938940
return;
939941
}
940942

@@ -992,8 +994,8 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc)
992994

993995
if (!(qc->flags & ATA_QCFLAG_RTF_FILLED)) {
994996
ata_dev_dbg(dev,
995-
"missing result TF: can't generate sense data\n");
996-
return;
997+
"Missing result TF: reporting aborted command\n");
998+
goto aborted;
997999
}
9981000

9991001
/* Use ata_to_sense_error() to map status register bits
@@ -1004,19 +1006,20 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc)
10041006
ata_to_sense_error(qc->ap->print_id, tf->status, tf->error,
10051007
&sense_key, &asc, &ascq);
10061008
ata_scsi_set_sense(dev, cmd, sense_key, asc, ascq);
1007-
} else {
1008-
/* Could not decode error */
1009-
ata_dev_warn(dev, "could not decode error status 0x%x err_mask 0x%x\n",
1010-
tf->status, qc->err_mask);
1011-
ata_scsi_set_sense(dev, cmd, ABORTED_COMMAND, 0, 0);
1012-
return;
1013-
}
10141009

1015-
block = ata_tf_read_block(&qc->result_tf, dev);
1016-
if (block == U64_MAX)
1010+
block = ata_tf_read_block(&qc->result_tf, dev);
1011+
if (block != U64_MAX)
1012+
scsi_set_sense_information(sb, SCSI_SENSE_BUFFERSIZE,
1013+
block);
10171014
return;
1015+
}
10181016

1019-
scsi_set_sense_information(sb, SCSI_SENSE_BUFFERSIZE, block);
1017+
/* Could not decode error */
1018+
ata_dev_warn(dev,
1019+
"Could not decode error 0x%x, status 0x%x (err_mask=0x%x)\n",
1020+
tf->error, tf->status, qc->err_mask);
1021+
aborted:
1022+
ata_scsi_set_sense(dev, cmd, ABORTED_COMMAND, 0, 0);
10201023
}
10211024

10221025
void ata_scsi_sdev_config(struct scsi_device *sdev)

0 commit comments

Comments
 (0)