diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-03-15 17:34:06 +0100 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2014-03-16 00:10:06 +0100 |
commit | 43d6464d410136f1c083a6df263bb71319eb2244 (patch) | |
tree | d71312c0b19da4394f8cb974d7229000616ea52f /hw | |
parent | 8002d8a662d4db7cc8c833ac960179e05f1280ed (diff) | |
download | qemu-43d6464d410136f1c083a6df263bb71319eb2244.tar.gz |
usbdump: fail early if dump file is not available
This allows for less less checking by the consumer and avoids
unnecessary work if the capture cannot be written anyway.
Signed-off-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'hw')
-rw-r--r-- | hw/usb/dev-unifying.c | 8 | ||||
-rw-r--r-- | hw/usb/dump.c | 10 | ||||
-rw-r--r-- | hw/usb/dump.h | 5 |
3 files changed, 15 insertions, 8 deletions
diff --git a/hw/usb/dev-unifying.c b/hw/usb/dev-unifying.c index 48479a07f4..68e2928b60 100644 --- a/hw/usb/dev-unifying.c +++ b/hw/usb/dev-unifying.c @@ -363,9 +363,7 @@ static void usb_ltunify_handle_control(USBDevice *dev, USBPacket *p, int desc_len = 0; const uint8_t *desc = NULL; - if (s->usb_dump_state) { - usb_dump_submit(s->usb_dump_state, p); - } + usb_dump_submit(s->usb_dump_state, p); /* handle basic requests such as DeviceRequest | USB_REQ_GET_DESCRIPTOR */ ret = usb_desc_handle_control(dev, p, request, value, index, length, data); @@ -409,9 +407,7 @@ static void usb_ltunify_handle_control(USBDevice *dev, USBPacket *p, } data_ready: - if (s->usb_dump_state) { - usb_dump_complete(s->usb_dump_state, p); - } + usb_dump_complete(s->usb_dump_state, p); } /* handle interrupt transfers (this device does not have a bulk/iso endpoint */ diff --git a/hw/usb/dump.c b/hw/usb/dump.c index 48da328126..eb4ce336e4 100644 --- a/hw/usb/dump.c +++ b/hw/usb/dump.c @@ -266,7 +266,10 @@ void usb_dump_submit(UsbDumpState *s, USBPacket *p) uint8_t pid = p->pid; uint8_t ep_type = p->ep->type; - assert(s != NULL); + /* fail early if not configured */ + if (!s || s->fd < 0) { + return; + } if (ep_type == USB_ENDPOINT_XFER_CONTROL) { // cannot get called for OUT @@ -294,7 +297,10 @@ void usb_dump_complete(UsbDumpState *s, USBPacket *p) uint8_t pid = p->pid; uint8_t ep_type = p->ep->type; - assert(s != NULL); + /* fail early if not configured */ + if (!s || s->fd < 0) { + return; + } if (ep_type == USB_ENDPOINT_XFER_CONTROL) { assert(pid == USB_TOKEN_IN || pid == USB_TOKEN_SETUP); diff --git a/hw/usb/dump.h b/hw/usb/dump.h index 1478fdc44c..08134e82e3 100644 --- a/hw/usb/dump.h +++ b/hw/usb/dump.h @@ -59,12 +59,17 @@ typedef struct UsbDumpState UsbDumpState; * direction, but setup_buf[0]. data is empty for PID == SETUP; for PID == IN, * data is of length setup_len. PID == OUT is not possible because handle_ctrl * is never called from that point. + * + * If s is NULL or if no dump file is available, no action is performed. */ void usb_dump_submit(UsbDumpState *s, USBPacket *p); + /* * complete (ctrl): setup_is irrelevant. If PID == SETUP, then the data was just * inserted by the "device" in handle_ctrl. Length is actual_length. If PID == * IN, then data is empty. PID == OUT is again not possible (see submit). + * + * If s is NULL or if no dump file is available, no action is performed. */ void usb_dump_complete(UsbDumpState *s, USBPacket *p); |