aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/usb
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2012-08-04 00:33:32 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2012-08-04 00:33:32 -0400
commit4e20db54c8134c5f967f5ca4d9efe0577b920041 (patch)
tree9397c300956a4f7945822241a4d70577c1837b9a /libmaple/usb
parent23918555b0eb87922b813590b8f8773acf834caf (diff)
downloadlibrambutan-4e20db54c8134c5f967f5ca4d9efe0577b920041.tar.gz
librambutan-4e20db54c8134c5f967f5ca4d9efe0577b920041.zip
usb_cdcacm: Set endpoint to NAK before checking byte count.
Fixes an (admittedly very unlikely) race condition. Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'libmaple/usb')
-rw-r--r--libmaple/usb/stm32f1/usb_cdcacm.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/libmaple/usb/stm32f1/usb_cdcacm.c b/libmaple/usb/stm32f1/usb_cdcacm.c
index 07cf9c4..2a942e5 100644
--- a/libmaple/usb/stm32f1/usb_cdcacm.c
+++ b/libmaple/usb/stm32f1/usb_cdcacm.c
@@ -540,11 +540,11 @@ static void vcomDataTxCb(void) {
}
static void vcomDataRxCb(void) {
- /* This following is safe since we set the RX endpoint to NAK
- * after each data packet received, and only set it to VALID when
- * all bytes have been read. */
- n_unread_bytes = usb_get_ep_rx_count(USB_CDCACM_RX_ENDP);
usb_set_ep_rx_stat(USB_CDCACM_RX_ENDP, USB_EP_STAT_RX_NAK);
+ n_unread_bytes = usb_get_ep_rx_count(USB_CDCACM_RX_ENDP);
+ /* This copy won't overwrite unread bytes, since we've set the RX
+ * endpoint to NAK, and will only set it to VALID when all bytes
+ * have been read. */
usb_copy_from_pma((uint8*)vcomBufferRx, n_unread_bytes,
USB_CDCACM_RX_ADDR);