From a14616c0963d9c03a0c612676de147b2526e297e Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 14 Dec 2019 19:13:14 +0100 Subject: [PATCH] usb_buf: Limit the maximum queue length to 3 elements If there are already three elements in the to-be-transmitted queue for the EP, let's free the first element of the queue. This is a clear indication that the USB host is not polling the endpoint regularly. Maybe there's no host application running at all? This should obsolete Change-Id Ie9ebdd2ff966f67c9afd1ed760f106558f0091ad Change-Id: Ie15183f16b22193ffdaf01845db2eae4c7f43c17 Closes: OS#4251 --- firmware/libcommon/source/usb_buf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/firmware/libcommon/source/usb_buf.c b/firmware/libcommon/source/usb_buf.c index 8ad5a0e9..7892d6eb 100644 --- a/firmware/libcommon/source/usb_buf.c +++ b/firmware/libcommon/source/usb_buf.c @@ -24,6 +24,7 @@ #include #define USB_ALLOC_SIZE 280 +#define USB_MAX_QLEN 3 static struct usb_buffered_ep usb_buffered_ep[BOARD_USB_NUMENDPOINTS]; @@ -78,6 +79,17 @@ int usb_buf_submit(struct msgb *msg) /* no need for irqsafe operation, as the usb_tx_queue is * processed only by the main loop context */ + + if (ep->queue_len > USB_MAX_QLEN) { + struct msgb *evict; + /* free the first pending buffer in the queue */ + TRACE_INFO("EP%02x: dropping first queue element (qlen=%u)\r\n", + ep->ep, ep->queue_len); + evict = msgb_dequeue_count(&ep->queue, &ep->queue_len); + OSMO_ASSERT(evict); + usb_buf_free(evict); + } + msgb_enqueue_count(&ep->queue, msg, &ep->queue_len); return 0; }