ChangeSet 1.1018.1.18, 2003/04/07 10:19:29-07:00, mdharm-usb@one-eyed-alien.net [PATCH] usb-storage: remove BUG/BUG_ON This patch changes BUG and BUG_ON to print error messages. It is done to be (a) a little more robust, and (b) complies with Linus' idea of no BUGs unless absolutely necessary. drivers/usb/storage/scsiglue.c | 20 +++++++++++++++----- drivers/usb/storage/transport.c | 9 +++++++-- drivers/usb/storage/transport.h | 2 +- drivers/usb/storage/usb.c | 5 ----- 4 files changed, 23 insertions(+), 13 deletions(-) diff -Nru a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c --- a/drivers/usb/storage/scsiglue.c Mon Apr 7 15:12:26 2003 +++ b/drivers/usb/storage/scsiglue.c Mon Apr 7 15:12:26 2003 @@ -141,13 +141,19 @@ static int usb_storage_queuecommand( Scsi_Cmnd *srb , void (*done)(Scsi_Cmnd *)) { struct us_data *us = (struct us_data *)srb->device->host->hostdata[0]; + int state = atomic_read(&us->sm_state); US_DEBUGP("queuecommand() called\n"); srb->host_scribble = (unsigned char *)us; /* enqueue the command */ - BUG_ON(atomic_read(&us->sm_state) != US_STATE_IDLE); - BUG_ON(us->srb != NULL); + if (state != US_STATE_IDLE || us->srb != NULL) { + printk(KERN_ERR USB_STORAGE "Error in %s: " + "state = %d, us->srb = %p\n", + __FUNCTION__, state, us->srb); + return SCSI_MLQUEUE_HOST_BUSY; + } + srb->scsi_done = done; us->srb = srb; @@ -175,8 +181,7 @@ return FAILED; } - usb_stor_abort_transport(us); - return SUCCESS; + return usb_stor_abort_transport(us); } /* This invokes the transport reset mechanism to reset the state of the @@ -185,10 +190,15 @@ static int usb_storage_device_reset( Scsi_Cmnd *srb ) { struct us_data *us = (struct us_data *)srb->device->host->hostdata[0]; + int state = atomic_read(&us->sm_state); int result; US_DEBUGP("device_reset() called\n" ); - BUG_ON(atomic_read(&us->sm_state) != US_STATE_IDLE); + if (state != US_STATE_IDLE) { + printk(KERN_ERR USB_STORAGE "Error in %s: " + "invalid state %d\n", __FUNCTION__, state); + return FAILED; + } /* set the state and release the lock */ atomic_set(&us->sm_state, US_STATE_RESETTING); diff -Nru a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c --- a/drivers/usb/storage/transport.c Mon Apr 7 15:12:26 2003 +++ b/drivers/usb/storage/transport.c Mon Apr 7 15:12:26 2003 @@ -692,7 +692,7 @@ /* Abort the currently running scsi command or device reset. * This must be called with scsi_lock(us->srb->host) held */ -void usb_stor_abort_transport(struct us_data *us) +int usb_stor_abort_transport(struct us_data *us) { struct Scsi_Host *host; int state = atomic_read(&us->sm_state); @@ -702,7 +702,11 @@ /* Normally the current state is RUNNING. If the control thread * hasn't even started processing this command, the state will be * IDLE. Anything else is a bug. */ - BUG_ON((state != US_STATE_RUNNING && state != US_STATE_IDLE)); + if (state != US_STATE_RUNNING && state != US_STATE_IDLE) { + printk(KERN_ERR USB_STORAGE "Error in %s: " + "invalid state %d\n", __FUNCTION__, state); + return FAILED; + } /* set state to abort and release the lock */ atomic_set(&us->sm_state, US_STATE_ABORTING); @@ -731,6 +735,7 @@ /* Reacquire the lock: note that us->srb is now NULL */ scsi_lock(host); + return SUCCESS; } /* diff -Nru a/drivers/usb/storage/transport.h b/drivers/usb/storage/transport.h --- a/drivers/usb/storage/transport.h Mon Apr 7 15:12:26 2003 +++ b/drivers/usb/storage/transport.h Mon Apr 7 15:12:26 2003 @@ -154,7 +154,7 @@ extern int usb_stor_Bulk_reset(struct us_data*); extern void usb_stor_invoke_transport(Scsi_Cmnd*, struct us_data*); -extern void usb_stor_abort_transport(struct us_data*); +extern int usb_stor_abort_transport(struct us_data*); extern int usb_stor_bulk_msg(struct us_data *us, void *data, unsigned int pipe, unsigned int len, unsigned int *act_len); diff -Nru a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c --- a/drivers/usb/storage/usb.c Mon Apr 7 15:12:26 2003 +++ b/drivers/usb/storage/usb.c Mon Apr 7 15:12:26 2003 @@ -935,11 +935,6 @@ us = usb_get_intfdata(intf); usb_set_intfdata(intf, NULL); - /* serious error -- we're attempting to disconnect an interface but - * cannot locate the local data structure - */ - BUG_ON(us == NULL); - /* set devices offline -- need host lock for this */ scsi_lock(us->host); list_for_each_entry(sdev, &us->host->my_devices, siblings)