From 43d6464d410136f1c083a6df263bb71319eb2244 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 15 Mar 2014 17:34:06 +0100 Subject: 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 --- hw/usb/dump.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'hw/usb/dump.c') 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); -- cgit v1.2.1