Skip to content

Commit f1a0743

Browse files
AlanSterngregkh
authored andcommitted
USB: storage: When a device returns no sense data, call it a Hardware Error
This patch (as1294) fixes a problem that has plagued users for several kernel releases. Some USB mass-storage devices don't return any sense data when they encounter certain kinds of errors. The SCSI layer interprets this to mean that the operation should be retried, and the same thing happens -- over and over again with no limit. In some circumstances (such as when a bus reset occurs) that is the right thing to do, but not here. The patch checks for this condition (a transport failure with no sense data) and changes the result code to DID_ERROR and the sense code to Hardware Error. This does get only a limited number of retries, and so the command will fail relatively quickly instead of getting stuck in an infinite loop. This fixes a large part of Bugzilla #14118. Signed-off-by: Alan Stern <[email protected]> Tested-by: Mantas Mikulenas <[email protected]> CC: stable <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a5f6005 commit f1a0743

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

drivers/usb/storage/transport.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -768,17 +768,32 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
768768
/* set the result so the higher layers expect this data */
769769
srb->result = SAM_STAT_CHECK_CONDITION;
770770

771-
/* If things are really okay, then let's show that. Zero
772-
* out the sense buffer so the higher layers won't realize
773-
* we did an unsolicited auto-sense. */
774-
if (result == USB_STOR_TRANSPORT_GOOD &&
775-
/* Filemark 0, ignore EOM, ILI 0, no sense */
771+
/* We often get empty sense data. This could indicate that
772+
* everything worked or that there was an unspecified
773+
* problem. We have to decide which.
774+
*/
775+
if ( /* Filemark 0, ignore EOM, ILI 0, no sense */
776776
(srb->sense_buffer[2] & 0xaf) == 0 &&
777777
/* No ASC or ASCQ */
778778
srb->sense_buffer[12] == 0 &&
779779
srb->sense_buffer[13] == 0) {
780-
srb->result = SAM_STAT_GOOD;
781-
srb->sense_buffer[0] = 0x0;
780+
781+
/* If things are really okay, then let's show that.
782+
* Zero out the sense buffer so the higher layers
783+
* won't realize we did an unsolicited auto-sense.
784+
*/
785+
if (result == USB_STOR_TRANSPORT_GOOD) {
786+
srb->result = SAM_STAT_GOOD;
787+
srb->sense_buffer[0] = 0x0;
788+
789+
/* If there was a problem, report an unspecified
790+
* hardware error to prevent the higher layers from
791+
* entering an infinite retry loop.
792+
*/
793+
} else {
794+
srb->result = DID_ERROR << 16;
795+
srb->sense_buffer[2] = HARDWARE_ERROR;
796+
}
782797
}
783798
}
784799

0 commit comments

Comments
 (0)