Skip to contentSkip to conversation

usb-storage: cancel I/O on reset

PATCH New Gerd Hoffmann 1 participant 1 message Jan 5, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb-storage: cancel I/O on reset

When resetting the usb-storage device we'll have to carefully cancel and clear any requests which might be in flight, otherwise we'll confuse the state machine.

---
 hw/usb-msd.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
hw/usb-msd.c +12 -0
index 4c06950..3147131 100644
@@ -278,6 +278,18 @@ static void usb_msd_handle_reset(USBDevice *dev)
     MSDState *s = (MSDState *)dev;
 
     DPRINTF("Reset\n");
+    if (s->req) {
+        scsi_req_cancel(s->req);
+    }
+    assert(s->req == NULL);
+
+    if (s->packet) {
+        USBPacket *p = s->packet;
+        s->packet = NULL;
+        p->result = USB_RET_STALL;
+        usb_packet_complete(dev, p);
+    }
+
     s->mode = USB_MSDM_CBW;
 }
 
Signature · 1 line
1.7.1