ChangeSet 1.1508.1.4, 2003/06/30 10:58:29-07:00, mdharm-usb@one-eyed-alien.net [PATCH] USB storage: avoid sending URBs when disconnecting This patch avoids sending URBs which are part of the reset system when the device is being disconnected. It also makes the control thread avoid starting anything for a device in that state. drivers/usb/storage/scsiglue.c | 8 ++++++-- drivers/usb/storage/transport.c | 4 ++++ drivers/usb/storage/usb.c | 8 +++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff -Nru a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c --- a/drivers/usb/storage/scsiglue.c Tue Jul 1 14:24:27 2003 +++ b/drivers/usb/storage/scsiglue.c Tue Jul 1 14:24:27 2003 @@ -166,7 +166,11 @@ /* lock the device pointers and do the reset */ down(&(us->dev_semaphore)); - result = us->transport_reset(us); + if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { + result = FAILED; + US_DEBUGP("No reset during disconnect\n"); + } else + result = us->transport_reset(us); up(&(us->dev_semaphore)); /* lock access to the state and clear it */ @@ -202,7 +206,7 @@ down(&(us->dev_semaphore)); if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { result = -EIO; - US_DEBUGP("Attempt to reset during disconnect\n"); + US_DEBUGP("No reset during disconnect\n"); } else if (us->pusb_dev->actconfig->desc.bNumInterfaces != 1) { result = -EBUSY; US_DEBUGP("Refusing to reset a multi-interface device\n"); diff -Nru a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c --- a/drivers/usb/storage/transport.c Tue Jul 1 14:24:27 2003 +++ b/drivers/usb/storage/transport.c Tue Jul 1 14:24:27 2003 @@ -1065,6 +1065,10 @@ schedule_timeout(HZ*6); set_current_state(TASK_RUNNING); down(&us->dev_semaphore); + if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { + US_DEBUGP("Reset interrupted by disconnect\n"); + return FAILED; + } US_DEBUGP("Soft reset: clearing bulk-in endpoint halt\n"); result = usb_stor_clear_halt(us, us->recv_bulk_pipe); diff -Nru a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c --- a/drivers/usb/storage/usb.c Tue Jul 1 14:24:27 2003 +++ b/drivers/usb/storage/usb.c Tue Jul 1 14:24:27 2003 @@ -338,10 +338,16 @@ /* lock the device pointers */ down(&(us->dev_semaphore)); + /* don't do anything if we are disconnecting */ + if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { + US_DEBUGP("No command during disconnect\n"); + us->srb->result = DID_BAD_TARGET << 16; + } + /* reject the command if the direction indicator * is UNKNOWN */ - if (us->srb->sc_data_direction == SCSI_DATA_UNKNOWN) { + else if (us->srb->sc_data_direction == SCSI_DATA_UNKNOWN) { US_DEBUGP("UNKNOWN data direction\n"); us->srb->result = DID_ERROR << 16; }