ChangeSet 1.883.3.7, 2002/12/16 10:49:56-08:00, mdharm-usb@one-eyed-alien.net

[PATCH] usb-storage: fixup interpret_urb_result()

This patch fixes interpret_urb_result in two major ways:
(1) Uses a switch() instead of nested if() statements
(2) Handle -EREMOTEIO to indicate a short scatter-gather transfer


diff -Nru a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
--- a/drivers/usb/storage/transport.c	Wed Dec 18 00:34:56 2002
+++ b/drivers/usb/storage/transport.c	Wed Dec 18 00:34:56 2002
@@ -480,7 +480,7 @@
 	status = usb_stor_msg_common(us);
 
 	/* return the actual length of the data transferred if no error */
-	if (status >= 0)
+	if (status == 0)
 		status = us->current_urb->actual_length;
 	return status;
 }
@@ -583,50 +583,52 @@
 
 	US_DEBUGP("Status code %d; transferred %u/%u\n",
 			result, partial, length);
+	switch (result) {
 
-	/* stalled */
-	if (result == -EPIPE) {
+	/* no error code; did we send all the data? */
+	case 0:
+		if (partial != length) {
+			US_DEBUGP("-- short transfer\n");
+			return USB_STOR_XFER_SHORT;
+		}
+
+		US_DEBUGP("-- transfer complete\n");
+		return USB_STOR_XFER_GOOD;
 
-		/* for non-bulk (i.e., control) endpoints, a stall indicates
-		 * a protocol error */
-		if (!usb_pipebulk(pipe)) {
+	/* stalled */
+	case -EPIPE:
+		/* for control endpoints, a stall indicates a protocol error */
+		if (usb_pipecontrol(pipe)) {
 			US_DEBUGP("-- stall on control pipe\n");
 			return USB_STOR_XFER_ERROR;
 		}
 
-		/* for a bulk endpoint, clear the stall */
+		/* for other sorts of endpoint, clear the stall */
 		US_DEBUGP("clearing endpoint halt for pipe 0x%x\n", pipe);
 		if (usb_stor_clear_halt(us, pipe) < 0)
 			return USB_STOR_XFER_ERROR;
 		return USB_STOR_XFER_STALLED;
-	}
 
 	/* NAK - that means we've retried this a few times already */
-	if (result == -ETIMEDOUT) {
+	case -ETIMEDOUT:
 		US_DEBUGP("-- device NAKed\n");
 		return USB_STOR_XFER_ERROR;
-	}
 
 	/* the transfer was cancelled, presumably by an abort */
-	if (result == -ENODEV) {
+	case -ENODEV:
 		US_DEBUGP("-- transfer cancelled\n");
 		return USB_STOR_XFER_ERROR;
-	}
+
+	/* short scatter-gather read transfer */
+	case -EREMOTEIO:
+		US_DEBUGP("-- short read transfer\n");
+		return USB_STOR_XFER_SHORT;
 
 	/* the catch-all error case */
-	if (result < 0) {
+	default:
 		US_DEBUGP("-- unknown error\n");
 		return USB_STOR_XFER_ERROR;
 	}
-
-	/* no error code; did we send all the data? */
-	if (partial != length) {
-		US_DEBUGP("-- transferred only %u bytes\n", partial);
-		return USB_STOR_XFER_SHORT;
-	}
-
-	US_DEBUGP("-- transfer complete\n");
-	return USB_STOR_XFER_GOOD;
 }
 
 /*
