[patch 57/60] usb-storage: automatically recognize bad residues

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Greg KH
Date: Monday, August 18, 2008 - 11:45 am

2.6.26-stable review patch.  If anyone has any objections, please let us know.

------------------
From: Alan Stern <stern@rowland.harvard.edu>

commit 59f4ff2ecff4cef36378928cec891785b402e80c upstream

This patch (as1119b) will help to reduce the clutter of usb-storage's
unusual_devs file by automatically detecting some devices that need
the IGNORE_RESIDUE flag.  The idea is that devices should never return
a non-zero residue for an INQUIRY or a READ CAPACITY command unless
they failed to transfer all the requested data.  So if one of these
commands transfers a standard amount of data but there is a positive
residue, we know that the residue is bogus and we can set the flag.

This fixes the problems reported in Bugzilla #11125.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Tested-by: Matthew Frost <artusemrys@sbcglobal.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/usb/storage/transport.c |   17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -1034,8 +1034,21 @@ int usb_stor_Bulk_transport(struct scsi_
 
 	/* try to compute the actual residue, based on how much data
 	 * was really transferred and what the device tells us */
-	if (residue) {
-		if (!(us->flags & US_FL_IGNORE_RESIDUE)) {
+	if (residue && !(us->flags & US_FL_IGNORE_RESIDUE)) {
+
+		/* Heuristically detect devices that generate bogus residues
+		 * by seeing what happens with INQUIRY and READ CAPACITY
+		 * commands.
+		 */
+		if (bcs->Status == US_BULK_STAT_OK &&
+				scsi_get_resid(srb) == 0 &&
+					((srb->cmnd[0] == INQUIRY &&
+						transfer_length == 36) ||
+					(srb->cmnd[0] == READ_CAPACITY &&
+						transfer_length == 8))) {
+			us->flags |= US_FL_IGNORE_RESIDUE;
+
+		} else {
 			residue = min(residue, transfer_length);
 			scsi_set_resid(srb, max(scsi_get_resid(srb),
 			                                       (int) residue));

-- 
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch 00/60] 2.6.26-stable review, Greg KH, (Mon Aug 18, 11:40 am)
[patch 01/60] mlock() fix return values, Greg KH, (Mon Aug 18, 11:41 am)
[patch 02/60] SCSI: ses: fix VPD inquiry overrun, Greg KH, (Mon Aug 18, 11:41 am)
[patch 06/60] vt8623fb: fix kernel oops, Greg KH, (Mon Aug 18, 11:41 am)
[patch 11/60] radeonfb: fix accel engine hangs, Greg KH, (Mon Aug 18, 11:42 am)
[patch 26/60] random32: seeding improvement, Greg KH, (Mon Aug 18, 11:43 am)
[patch 28/60] sparc64: FUTEX_OP_ANDN fix, Greg KH, (Mon Aug 18, 11:44 am)
[patch 41/60] x86: amd opteron TOM2 mask val fix, Greg KH, (Mon Aug 18, 11:44 am)
[patch 44/60] radeon: misc corrections, Greg KH, (Mon Aug 18, 11:45 am)
[patch 45/60] cs5520: add enablebits checking, Greg KH, (Mon Aug 18, 11:45 am)
[patch 50/60] sparc64: Implement IRQ stacks., Greg KH, (Mon Aug 18, 11:45 am)
[patch 52/60] x86: fix spin_is_contended(), Greg KH, (Mon Aug 18, 11:45 am)
[patch 57/60] usb-storage: automatically recognize bad res ..., Greg KH, (Mon Aug 18, 11:45 am)