diff options
author | tzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2006-09-06 05:03:15 +0000 |
---|---|---|
committer | tzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2006-09-06 05:03:15 +0000 |
commit | efb34c4af7ad5a96c2733aee1e8ee33fbe4cdd69 (patch) | |
tree | 0e454a65ae1dc6132406582b89c996571086f203 /xpp/xpp_usb.c | |
parent | 69b219a4a6bc515e6fb0864427ab2d925d9ba497 (diff) |
Better USB error handling: move "pending_writes" check earlier.
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@1407 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'xpp/xpp_usb.c')
-rw-r--r-- | xpp/xpp_usb.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/xpp/xpp_usb.c b/xpp/xpp_usb.c index 605ddd8..89571c3 100644 --- a/xpp/xpp_usb.c +++ b/xpp/xpp_usb.c @@ -292,7 +292,18 @@ static int xusb_packet_send(xbus_t *xbus, xpacket_t *pack) if(!xusb->present) { NOTICE("tried to send packets to non-exitant USB device. Ignored\n"); ret = -ENODEV; - goto out; + goto freepack; + } + /* + * If something really bad happend, do not overflow the USB stack + */ + if(atomic_read(&xusb->pending_writes) > MAX_PENDING_WRITES) { + static int rate_limit; + + if((rate_limit++ % 1000) < 10) + ERR("%s: %s: more than %d pending writes. Dropping.\n", __FUNCTION__, xbus->busname, MAX_PENDING_WRITES); + ret = -ENODEV; + goto freepack; } size = PACKET_LEN(pack); xusb_ep = &xusb->endpoints[XUSB_SEND]; @@ -300,7 +311,7 @@ static int xusb_packet_send(xbus_t *xbus, xpacket_t *pack) if (!urb) { ERR("No free urbs available\n"); ret = -ENOMEM; - goto out; + goto freepack; } packet_debug("USB_PACKET_SEND", xusb, pack); @@ -315,22 +326,15 @@ static int xusb_packet_send(xbus_t *xbus, xpacket_t *pack) ERR("%s: failed submit_urb: %d\n", __FUNCTION__, ret); xpp_urb_delete(urb); ret = -EBADF; - goto out; + goto freepack; } atomic_inc(&xusb->pending_writes); - if(atomic_read(&xusb->pending_writes) > MAX_PENDING_WRITES) { - static int rate_limit; - - if((rate_limit++ % 1000) < 10) - ERR("%s: %s: more than %d pending writes. Dropping.\n", __FUNCTION__, xbus->busname, MAX_PENDING_WRITES); - ret = -ENODEV; - } if(pack->content.opcode == XPROTO_NAME(GLOBAL,PCM_WRITE)) XUSB_COUNTER(xusb, PCM_WRITES)++; -out: +freepack: + xbus->ops->packet_free(xbus, pack); // FIXME: eventually will be done in the urb callback if(ret < 0) XUSB_COUNTER(xusb, TX_ERRORS)++; - xbus->ops->packet_free(xbus, pack); // FIXME: eventually will be done in the urb callback return ret; } |