ChangeSet 1.855.9.12, 2002/11/05 11:17:27-08:00, mdharm-usb@one-eyed-alien.net

[PATCH] USB storage: check for abort at higher levels

This patch adds tests for an aborted command to higher-level functions.
This allows faster exit from a couple of paths and will allow code
consolidation in the lower-level transport functions.


diff -Nru a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
--- a/drivers/usb/storage/isd200.c	Tue Nov  5 16:10:18 2002
+++ b/drivers/usb/storage/isd200.c	Tue Nov  5 16:10:18 2002
@@ -818,11 +818,22 @@
 {
 	int need_auto_sense = 0;
 	int transferStatus;
+	int result;
 
 	/* send the command to the transport layer */
 	srb->resid = 0;
 	transferStatus = isd200_Bulk_transport(us, srb, ataCdb,
 					       sizeof(ataCdb->generic));
+
+	/* if the command gets aborted by the higher layers, we need to
+	 * short-circuit all other processing
+	 */
+	if (atomic_read(&us->sm_state) == US_STATE_ABORTING) {
+		US_DEBUGP("-- transport indicates command was aborted\n");
+		srb->result = DID_ABORT << 16;
+		return;
+	}
+
 	switch (transferStatus) {
 
 	case ISD200_TRANSPORT_GOOD:
@@ -866,9 +877,14 @@
        
 	}
 
-	if (need_auto_sense)
-		if (isd200_read_regs(us) == ISD200_GOOD)
+	if (need_auto_sense) {
+		result = isd200_read_regs(us);
+		if (atomic_read(&us->sm_state) == US_STATE_ABORTING) {
+			US_DEBUGP("-- auto-sense aborted\n");
+			srb->result = DID_ABORT << 16;
+		} else if (result == ISD200_GOOD)
 			isd200_build_sense(us, srb);
+	}
 
 	/* Regardless of auto-sense, if we _know_ we have an error
 	 * condition, show that in the result code
diff -Nru a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
--- a/drivers/usb/storage/transport.c	Tue Nov  5 16:10:18 2002
+++ b/drivers/usb/storage/transport.c	Tue Nov  5 16:10:18 2002
@@ -790,13 +790,14 @@
 	/* if the command gets aborted by the higher layers, we need to
 	 * short-circuit all other processing
 	 */
-	if (result == USB_STOR_TRANSPORT_ABORTED) {
+	if (atomic_read(&us->sm_state) == US_STATE_ABORTING) {
 		US_DEBUGP("-- transport indicates command was aborted\n");
 		srb->result = DID_ABORT << 16;
 		return;
 	}
 
 	/* if there is a transport error, reset and don't auto-sense */
+	/* What if we want to abort during the reset? */
 	if (result == USB_STOR_TRANSPORT_ERROR) {
 		US_DEBUGP("-- transport indicates error, resetting\n");
 		us->transport_reset(us);
@@ -904,7 +905,7 @@
 		srb->sc_data_direction = old_sc_data_direction;
 		memcpy(srb->cmnd, old_cmnd, MAX_COMMAND_SIZE);
 
-		if (temp_result == USB_STOR_TRANSPORT_ABORTED) {
+		if (atomic_read(&us->sm_state) == US_STATE_ABORTING) {
 			US_DEBUGP("-- auto-sense aborted\n");
 			srb->result = DID_ABORT << 16;
 			return;
@@ -917,6 +918,7 @@
 			 * auto-sense is perfectly valid
 			 */
 			if (!(us->flags & US_FL_SCM_MULT_TARG)) {
+				/* What if we try to abort during the reset? */
 				us->transport_reset(us);
 			}
 			srb->result = DID_ERROR << 16;
