[zaptel-commits] tzafrir: trunk r1407 - /trunk/xpp/xpp_usb.c

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Tue Sep 5 22:03:16 MST 2006


Author: tzafrir
Date: Wed Sep  6 00:03:15 2006
New Revision: 1407

URL: http://svn.digium.com/view/zaptel?rev=1407&view=rev
Log:
Better USB error handling: move "pending_writes" check earlier.

Modified:
    trunk/xpp/xpp_usb.c

Modified: trunk/xpp/xpp_usb.c
URL: http://svn.digium.com/view/zaptel/trunk/xpp/xpp_usb.c?rev=1407&r1=1406&r2=1407&view=diff
==============================================================================
--- trunk/xpp/xpp_usb.c (original)
+++ trunk/xpp/xpp_usb.c Wed Sep  6 00:03:15 2006
@@ -292,7 +292,18 @@
 	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 @@
 	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 @@
 			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;
 }
 



More information about the zaptel-commits mailing list