summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
authorNamyoon Woo <namyoon@chromium.org>2019-04-22 13:28:40 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-04-26 00:17:47 -0700
commit8c50dc29cb6f7cdb077fe9ba49425404ae98207b (patch)
treef275ae386bc06967ebfa3095b616f3926ceb51d1 /chip
parent0a60e8dbd01b39ca1c4fde2523f0961c5a07fc35 (diff)
downloadchrome-ec-8c50dc29cb6f7cdb077fe9ba49425404ae98207b.tar.gz
chip/g: prevent USB read queue overflow
CR50 should check whether USB RX queue has enough space for host data. If not, it schedules to retry it in another deferred call. BUG=b:130908211 BRANCH=cr50 TEST=manually ran "echo 'help' > /dev/ttyUSB0" more than 30 times. Without this CL, it used to break cr50 console input, and it worked as if it is 'read-only'. After applying this CL, cr50 console input works normal even after excessive input stream. Change-Id: Ieace84b51c31800b52d2c4a9334e6ffe7888e592 Signed-off-by: Namyoon Woo <namyoon@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1576326 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Mary Ruthven <mruthven@chromium.org>
Diffstat (limited to 'chip')
-rw-r--r--chip/g/usart.c2
-rw-r--r--chip/g/usb-stream.c2
-rw-r--r--chip/g/usb_console.c6
3 files changed, 8 insertions, 2 deletions
diff --git a/chip/g/usart.c b/chip/g/usart.c
index 3e5ba3a88a..e3e83dd1f2 100644
--- a/chip/g/usart.c
+++ b/chip/g/usart.c
@@ -184,7 +184,7 @@ static void uart_written(struct consumer const *consumer, size_t count)
}
#endif
- if (uartn_tx_ready(config->uart), queue_count(consumer->queue))
+ if (uartn_tx_ready(config->uart) && queue_count(consumer->queue))
uartn_tx_start(config->uart);
}
diff --git a/chip/g/usb-stream.c b/chip/g/usb-stream.c
index 94c8c2e9f7..4d552913e3 100644
--- a/chip/g/usb-stream.c
+++ b/chip/g/usb-stream.c
@@ -88,6 +88,8 @@ int rx_stream_handler(struct usb_stream_config const *config)
if (!rx_left) {
rx_handled = 0;
usb_enable_rx(config, config->rx_size);
+ } else {
+ hook_call_deferred(config->deferred_rx, 0);
}
return rx_handled;
}
diff --git a/chip/g/usb_console.c b/chip/g/usb_console.c
index 3904c5968a..11bef1de89 100644
--- a/chip/g/usb_console.c
+++ b/chip/g/usb_console.c
@@ -100,6 +100,9 @@ static inline int rx_fifo_is_ready(void)
return (ep_out_desc.flags & DOEPDMA_BS_MASK) == DOEPDMA_BS_DMA_DONE;
}
+static void rx_fifo_handler(void);
+DECLARE_DEFERRED(rx_fifo_handler);
+
/*
* This function tries to shove new bytes from the USB host into the queue for
* consumption elsewhere. It is invoked either by a HW interrupt (telling us we
@@ -160,9 +163,10 @@ static void rx_fifo_handler(void)
if (!rx_left) {
rx_handled = 0;
usb_enable_rx(USB_MAX_PACKET_SIZE);
+ } else {
+ hook_call_deferred(&rx_fifo_handler_data, 0);
}
}
-DECLARE_DEFERRED(rx_fifo_handler);
/* Rx/OUT interrupt handler */
static void con_ep_rx(void)