Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ata: libata-scsi: Return aborted command when missing sense and result TF

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: 816be86c7993 ("ata: libata-scsi: Check ATA_QCFLAG_RTF_FILLED before using result_tf")
Cc: stable@vger.kernel.org
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>

+11 -7
+11 -7
drivers/ata/libata-scsi.c
··· 938 938 if (!(qc->flags & ATA_QCFLAG_RTF_FILLED)) { 939 939 ata_dev_dbg(dev, 940 940 "missing result TF: can't generate ATA PT sense data\n"); 941 + if (qc->err_mask) 942 + ata_scsi_set_sense(dev, cmd, ABORTED_COMMAND, 0, 0); 941 943 return; 942 944 } 943 945 ··· 994 992 995 993 if (!(qc->flags & ATA_QCFLAG_RTF_FILLED)) { 996 994 ata_dev_dbg(dev, 997 - "missing result TF: can't generate sense data\n"); 998 - return; 995 + "Missing result TF: reporting aborted command\n"); 996 + goto aborted; 999 997 } 1000 998 1001 999 /* Use ata_to_sense_error() to map status register bits ··· 1006 1004 ata_to_sense_error(tf->status, tf->error, 1007 1005 &sense_key, &asc, &ascq); 1008 1006 ata_scsi_set_sense(dev, cmd, sense_key, asc, ascq); 1009 - } else { 1010 - /* Could not decode error */ 1011 - ata_dev_warn(dev, "could not decode error status 0x%x err_mask 0x%x\n", 1012 - tf->status, qc->err_mask); 1013 - ata_scsi_set_sense(dev, cmd, ABORTED_COMMAND, 0, 0); 1014 1007 return; 1015 1008 } 1009 + 1010 + /* Could not decode error */ 1011 + ata_dev_warn(dev, 1012 + "Could not decode error 0x%x, status 0x%x (err_mask=0x%x)\n", 1013 + tf->error, tf->status, qc->err_mask); 1014 + aborted: 1015 + ata_scsi_set_sense(dev, cmd, ABORTED_COMMAND, 0, 0); 1016 1016 } 1017 1017 1018 1018 void ata_scsi_sdev_config(struct scsi_device *sdev)