Commit b594df6e authored by Matthew Dharm's avatar Matthew Dharm Committed by Greg Kroah-Hartman

[PATCH] USB Storage: Remove unnecessary state testing

This patch started as as405 from Alan Stern.  It has been re-generated
against the current tip of the BK tree.

For quite a while we've had a bunch of state-transition testing code in the
driver, to report if anything bad ever happens (like the SCSI midlayer
trying to queue a second command before the first one finishes).  None of
those tests triggered in a very long time; this aspect of the code appears
to be extremely stable.

So this patch removes all those tests for illegal values of us->sm_state.
It turns out that sm_state was used only for one other purpose: to check
whether a command had timed out and caused a SCSI abort.  That piece of
information can easily be stored in a single new bitflag (which is called
calling US_FLIDX_TIMED_OUT) and doing so makes us->sm_state completely
unused.  Hence the patch removes it from the structure.
Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarMatthew Dharm <mdharm-usb@one-eyed-alien.net>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 154252fc
...@@ -555,7 +555,7 @@ static void isd200_invoke_transport( struct us_data *us, ...@@ -555,7 +555,7 @@ static void isd200_invoke_transport( struct us_data *us,
/* if the command gets aborted by the higher layers, we need to /* if the command gets aborted by the higher layers, we need to
* short-circuit all other processing * short-circuit all other processing
*/ */
if (us->sm_state == US_STATE_ABORTING) { if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
US_DEBUGP("-- command was aborted\n"); US_DEBUGP("-- command was aborted\n");
goto Handle_Abort; goto Handle_Abort;
} }
...@@ -602,7 +602,7 @@ static void isd200_invoke_transport( struct us_data *us, ...@@ -602,7 +602,7 @@ static void isd200_invoke_transport( struct us_data *us,
if (need_auto_sense) { if (need_auto_sense) {
result = isd200_read_regs(us); result = isd200_read_regs(us);
if (us->sm_state == US_STATE_ABORTING) { if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
US_DEBUGP("-- auto-sense aborted\n"); US_DEBUGP("-- auto-sense aborted\n");
goto Handle_Abort; goto Handle_Abort;
} }
......
...@@ -173,10 +173,9 @@ static int queuecommand(struct scsi_cmnd *srb, ...@@ -173,10 +173,9 @@ static int queuecommand(struct scsi_cmnd *srb,
srb->host_scribble = (unsigned char *)us; srb->host_scribble = (unsigned char *)us;
/* check for state-transition errors */ /* check for state-transition errors */
if (us->sm_state != US_STATE_IDLE || us->srb != NULL) { if (us->srb != NULL) {
printk(KERN_ERR USB_STORAGE "Error in %s: " printk(KERN_ERR USB_STORAGE "Error in %s: us->srb = %p\n",
"state = %d, us->srb = %p\n", __FUNCTION__, us->srb);
__FUNCTION__, us->sm_state, us->srb);
return SCSI_MLQUEUE_HOST_BUSY; return SCSI_MLQUEUE_HOST_BUSY;
} }
...@@ -200,7 +199,7 @@ static int queuecommand(struct scsi_cmnd *srb, ...@@ -200,7 +199,7 @@ static int queuecommand(struct scsi_cmnd *srb,
* Error handling functions * Error handling functions
***********************************************************************/ ***********************************************************************/
/* Command abort */ /* Command timeout and abort */
/* This is always called with scsi_lock(srb->host) held */ /* This is always called with scsi_lock(srb->host) held */
static int command_abort(struct scsi_cmnd *srb ) static int command_abort(struct scsi_cmnd *srb )
{ {
...@@ -215,22 +214,12 @@ static int command_abort(struct scsi_cmnd *srb ) ...@@ -215,22 +214,12 @@ static int command_abort(struct scsi_cmnd *srb )
return FAILED; return FAILED;
} }
/* Normally the current state is RUNNING. If the control thread /* Set the TIMED_OUT bit. Also set the ABORTING bit, but only if
* hasn't even started processing this command, the state will be
* IDLE. Anything else is a bug. */
if (us->sm_state != US_STATE_RUNNING
&& us->sm_state != US_STATE_IDLE) {
printk(KERN_ERR USB_STORAGE "Error in %s: "
"invalid state %d\n", __FUNCTION__, us->sm_state);
return FAILED;
}
/* Set state to ABORTING and set the ABORTING bit, but only if
* a device reset isn't already in progress (to avoid interfering * a device reset isn't already in progress (to avoid interfering
* with the reset). To prevent races with auto-reset, we must * with the reset). To prevent races with auto-reset, we must
* stop any ongoing USB transfers while still holding the host * stop any ongoing USB transfers while still holding the host
* lock. */ * lock. */
us->sm_state = US_STATE_ABORTING; set_bit(US_FLIDX_TIMED_OUT, &us->flags);
if (!test_bit(US_FLIDX_RESETTING, &us->flags)) { if (!test_bit(US_FLIDX_RESETTING, &us->flags)) {
set_bit(US_FLIDX_ABORTING, &us->flags); set_bit(US_FLIDX_ABORTING, &us->flags);
usb_stor_stop_transport(us); usb_stor_stop_transport(us);
...@@ -243,6 +232,7 @@ static int command_abort(struct scsi_cmnd *srb ) ...@@ -243,6 +232,7 @@ static int command_abort(struct scsi_cmnd *srb )
/* Reacquire the lock and allow USB transfers to resume */ /* Reacquire the lock and allow USB transfers to resume */
scsi_lock(host); scsi_lock(host);
clear_bit(US_FLIDX_ABORTING, &us->flags); clear_bit(US_FLIDX_ABORTING, &us->flags);
clear_bit(US_FLIDX_TIMED_OUT, &us->flags);
return SUCCESS; return SUCCESS;
} }
...@@ -255,14 +245,7 @@ static int device_reset(struct scsi_cmnd *srb) ...@@ -255,14 +245,7 @@ static int device_reset(struct scsi_cmnd *srb)
int result; int result;
US_DEBUGP("%s called\n", __FUNCTION__); US_DEBUGP("%s called\n", __FUNCTION__);
if (us->sm_state != US_STATE_IDLE) {
printk(KERN_ERR USB_STORAGE "Error in %s: "
"invalid state %d\n", __FUNCTION__, us->sm_state);
return FAILED;
}
/* set the state and release the lock */
us->sm_state = US_STATE_RESETTING;
scsi_unlock(srb->device->host); scsi_unlock(srb->device->host);
/* lock the device pointers and do the reset */ /* lock the device pointers and do the reset */
...@@ -274,9 +257,8 @@ static int device_reset(struct scsi_cmnd *srb) ...@@ -274,9 +257,8 @@ static int device_reset(struct scsi_cmnd *srb)
result = us->transport_reset(us); result = us->transport_reset(us);
up(&(us->dev_semaphore)); up(&(us->dev_semaphore));
/* lock access to the state and clear it */ /* lock the host for the return */
scsi_lock(srb->device->host); scsi_lock(srb->device->host);
us->sm_state = US_STATE_IDLE;
return result; return result;
} }
...@@ -290,14 +272,7 @@ static int bus_reset(struct scsi_cmnd *srb) ...@@ -290,14 +272,7 @@ static int bus_reset(struct scsi_cmnd *srb)
int result, rc; int result, rc;
US_DEBUGP("%s called\n", __FUNCTION__); US_DEBUGP("%s called\n", __FUNCTION__);
if (us->sm_state != US_STATE_IDLE) {
printk(KERN_ERR USB_STORAGE "Error in %s: "
"invalid state %d\n", __FUNCTION__, us->sm_state);
return FAILED;
}
/* set the state and release the lock */
us->sm_state = US_STATE_RESETTING;
scsi_unlock(srb->device->host); scsi_unlock(srb->device->host);
/* The USB subsystem doesn't handle synchronisation between /* The USB subsystem doesn't handle synchronisation between
...@@ -325,9 +300,8 @@ static int bus_reset(struct scsi_cmnd *srb) ...@@ -325,9 +300,8 @@ static int bus_reset(struct scsi_cmnd *srb)
} }
up(&(us->dev_semaphore)); up(&(us->dev_semaphore));
/* lock access to the state and clear it */ /* lock the host for the return */
scsi_lock(srb->device->host); scsi_lock(srb->device->host);
us->sm_state = US_STATE_IDLE;
return result < 0 ? FAILED : SUCCESS; return result < 0 ? FAILED : SUCCESS;
} }
......
...@@ -537,7 +537,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) ...@@ -537,7 +537,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
/* if the command gets aborted by the higher layers, we need to /* if the command gets aborted by the higher layers, we need to
* short-circuit all other processing * short-circuit all other processing
*/ */
if (us->sm_state == US_STATE_ABORTING) { if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
US_DEBUGP("-- command was aborted\n"); US_DEBUGP("-- command was aborted\n");
goto Handle_Abort; goto Handle_Abort;
} }
...@@ -665,7 +665,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) ...@@ -665,7 +665,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
srb->cmd_len = old_cmd_len; srb->cmd_len = old_cmd_len;
memcpy(srb->cmnd, old_cmnd, MAX_COMMAND_SIZE); memcpy(srb->cmnd, old_cmnd, MAX_COMMAND_SIZE);
if (us->sm_state == US_STATE_ABORTING) { if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
US_DEBUGP("-- auto-sense aborted\n"); US_DEBUGP("-- auto-sense aborted\n");
goto Handle_Abort; goto Handle_Abort;
} }
......
...@@ -318,8 +318,8 @@ static int usb_stor_control_thread(void * __us) ...@@ -318,8 +318,8 @@ static int usb_stor_control_thread(void * __us)
/* lock access to the state */ /* lock access to the state */
scsi_lock(host); scsi_lock(host);
/* has the command been aborted *already* ? */ /* has the command timed out *already* ? */
if (us->sm_state == US_STATE_ABORTING) { if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
us->srb->result = DID_ABORT << 16; us->srb->result = DID_ABORT << 16;
goto SkipForAbort; goto SkipForAbort;
} }
...@@ -330,8 +330,6 @@ static int usb_stor_control_thread(void * __us) ...@@ -330,8 +330,6 @@ static int usb_stor_control_thread(void * __us)
goto SkipForDisconnect; goto SkipForDisconnect;
} }
/* set the state and release the lock */
us->sm_state = US_STATE_RUNNING;
scsi_unlock(host); scsi_unlock(host);
/* reject the command if the direction indicator /* reject the command if the direction indicator
...@@ -392,16 +390,15 @@ static int usb_stor_control_thread(void * __us) ...@@ -392,16 +390,15 @@ static int usb_stor_control_thread(void * __us)
/* If an abort request was received we need to signal that /* If an abort request was received we need to signal that
* the abort has finished. The proper test for this is * the abort has finished. The proper test for this is
* sm_state == US_STATE_ABORTING, not srb->result == DID_ABORT, * the TIMED_OUT flag, not srb->result == DID_ABORT, because
* because an abort request might be received after all the * a timeout/abort request might be received after all the
* USB processing was complete. */ * USB processing was complete. */
if (us->sm_state == US_STATE_ABORTING) if (test_bit(US_FLIDX_TIMED_OUT, &us->flags))
complete(&(us->notify)); complete(&(us->notify));
/* empty the queue, reset the state, and release the lock */ /* finished working on this command */
SkipForDisconnect: SkipForDisconnect:
us->srb = NULL; us->srb = NULL;
us->sm_state = US_STATE_IDLE;
scsi_unlock(host); scsi_unlock(host);
/* unlock the device pointers */ /* unlock the device pointers */
...@@ -801,7 +798,6 @@ static int usb_stor_acquire_resources(struct us_data *us) ...@@ -801,7 +798,6 @@ static int usb_stor_acquire_resources(struct us_data *us)
us->host->hostdata[0] = (unsigned long) us; us->host->hostdata[0] = (unsigned long) us;
/* Start up our control thread */ /* Start up our control thread */
us->sm_state = US_STATE_IDLE;
p = kernel_thread(usb_stor_control_thread, us, CLONE_VM); p = kernel_thread(usb_stor_control_thread, us, CLONE_VM);
if (p < 0) { if (p < 0) {
printk(KERN_WARNING USB_STORAGE printk(KERN_WARNING USB_STORAGE
...@@ -829,7 +825,6 @@ void usb_stor_release_resources(struct us_data *us) ...@@ -829,7 +825,6 @@ void usb_stor_release_resources(struct us_data *us)
/* Wait for the thread to be idle */ /* Wait for the thread to be idle */
down(&us->dev_semaphore); down(&us->dev_semaphore);
US_DEBUGP("-- sending exit command to thread\n"); US_DEBUGP("-- sending exit command to thread\n");
BUG_ON(us->sm_state != US_STATE_IDLE);
/* If the SCSI midlayer queued a final command just before /* If the SCSI midlayer queued a final command just before
* scsi_remove_host() was called, us->srb might not be * scsi_remove_host() was called, us->srb might not be
......
...@@ -83,14 +83,9 @@ struct us_unusual_dev { ...@@ -83,14 +83,9 @@ struct us_unusual_dev {
#define ABORTING_OR_DISCONNECTING ((1UL << US_FLIDX_ABORTING) | \ #define ABORTING_OR_DISCONNECTING ((1UL << US_FLIDX_ABORTING) | \
(1UL << US_FLIDX_DISCONNECTING)) (1UL << US_FLIDX_DISCONNECTING))
#define US_FLIDX_RESETTING 22 /* 0x00400000 device reset in progress */ #define US_FLIDX_RESETTING 22 /* 0x00400000 device reset in progress */
#define US_FLIDX_TIMED_OUT 23 /* 0x00800000 SCSI midlayer timed out */
/* processing state machine states */
#define US_STATE_IDLE 1
#define US_STATE_RUNNING 2
#define US_STATE_RESETTING 3
#define US_STATE_ABORTING 4
#define USB_STOR_STRING_LEN 32 #define USB_STOR_STRING_LEN 32
/* /*
...@@ -148,7 +143,6 @@ struct us_data { ...@@ -148,7 +143,6 @@ struct us_data {
/* thread information */ /* thread information */
int pid; /* control thread */ int pid; /* control thread */
int sm_state; /* what we are doing */
/* control and bulk communications data */ /* control and bulk communications data */
struct urb *current_urb; /* USB requests */ struct urb *current_urb; /* USB requests */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment