usb-storage: add usb_msd_packet_complete()

Factor out packet completion to a separate function which
cares to get the MSDState->packet update right.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Gerd Hoffmann 2012-05-22 14:30:20 +02:00
parent 0659879e6e
commit 1e6ed80b90

View File

@ -200,6 +200,18 @@ static void usb_msd_send_status(MSDState *s, USBPacket *p)
memset(&s->csw, 0, sizeof(s->csw)); memset(&s->csw, 0, sizeof(s->csw));
} }
static void usb_msd_packet_complete(MSDState *s)
{
USBPacket *p = s->packet;
/* Set s->packet to NULL before calling usb_packet_complete
because another request may be issued before
usb_packet_complete returns. */
DPRINTF("Packet complete %p\n", p);
s->packet = NULL;
usb_packet_complete(&s->dev, p);
}
static void usb_msd_transfer_data(SCSIRequest *req, uint32_t len) static void usb_msd_transfer_data(SCSIRequest *req, uint32_t len)
{ {
MSDState *s = DO_UPCAST(MSDState, dev.qdev, req->bus->qbus.parent); MSDState *s = DO_UPCAST(MSDState, dev.qdev, req->bus->qbus.parent);
@ -212,12 +224,7 @@ static void usb_msd_transfer_data(SCSIRequest *req, uint32_t len)
usb_msd_copy_data(s, p); usb_msd_copy_data(s, p);
p = s->packet; p = s->packet;
if (p && p->result == p->iov.size) { if (p && p->result == p->iov.size) {
/* Set s->packet to NULL before calling usb_packet_complete usb_msd_packet_complete(s);
because another request may be issued before
usb_packet_complete returns. */
DPRINTF("Packet complete %p\n", p);
s->packet = NULL;
usb_packet_complete(&s->dev, p);
} }
} }
} }
@ -250,8 +257,7 @@ static void usb_msd_command_complete(SCSIRequest *req, uint32_t status, size_t r
s->mode = USB_MSDM_CSW; s->mode = USB_MSDM_CSW;
} }
} }
s->packet = NULL; usb_msd_packet_complete(s);
usb_packet_complete(&s->dev, p);
} else if (s->data_len == 0) { } else if (s->data_len == 0) {
s->mode = USB_MSDM_CSW; s->mode = USB_MSDM_CSW;
} }
@ -281,10 +287,8 @@ static void usb_msd_handle_reset(USBDevice *dev)
assert(s->req == NULL); assert(s->req == NULL);
if (s->packet) { if (s->packet) {
USBPacket *p = s->packet; s->packet->result = USB_RET_STALL;
s->packet = NULL; usb_msd_packet_complete(s);
p->result = USB_RET_STALL;
usb_packet_complete(dev, p);
} }
s->mode = USB_MSDM_CBW; s->mode = USB_MSDM_CBW;