From 7a562649d9bc6e42df079696410fff7091410656 Mon Sep 17 00:00:00 2001 From: arighi Date: Wed, 29 Sep 2010 13:42:04 +0000 Subject: [PATCH] STM32: USB: move the buffer alignment asserts into the appropriate functions git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4349 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/cortex-m3/drv/usb_stm32.c | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/bertos/cpu/cortex-m3/drv/usb_stm32.c b/bertos/cpu/cortex-m3/drv/usb_stm32.c index 154f0a04..6e975749 100644 --- a/bertos/cpu/cortex-m3/drv/usb_stm32.c +++ b/bertos/cpu/cortex-m3/drv/usb_stm32.c @@ -675,12 +675,18 @@ out: \ static stm32_UsbIoStatus __usb_ep_read(int ep, void *buffer, ssize_t size, void (*complete)(int)) { - if (UNLIKELY(ep >= ENP_MAX_NUMB)) + if (UNLIKELY((ep >= ENP_MAX_NUMB) || (ep & 0x01))) { + LOG_ERR("%s: invalid EP number %d\n", __func__, ep); + ASSERT(0); + return STALLED; + } + if (UNLIKELY((size_t)buffer & 0x03)) + { + LOG_ERR("%s: unaligned buffer @ %p\n", __func__, buffer); ASSERT(0); return STALLED; } - ASSERT(!(ep & 0x01)); return USB_EP_IO(ep, read, buffer, size, complete); } @@ -688,12 +694,18 @@ __usb_ep_read(int ep, void *buffer, ssize_t size, void (*complete)(int)) static stm32_UsbIoStatus __usb_ep_write(int ep, const void *buffer, ssize_t size, void (*complete)(int)) { - if (UNLIKELY(ep >= ENP_MAX_NUMB)) + if (UNLIKELY((ep >= ENP_MAX_NUMB) || !(ep & 0x01))) { + LOG_ERR("%s: invalid EP number %d\n", __func__, ep); + ASSERT(0); + return STALLED; + } + if (UNLIKELY((size_t)buffer & 0x03)) + { + LOG_ERR("%s: unaligned buffer @ %p\n", __func__, buffer); ASSERT(0); return STALLED; } - ASSERT(ep & 0x01); return USB_EP_IO(ep, write, buffer, size, complete); } @@ -1103,12 +1115,6 @@ ssize_t usb_endpointRead(int ep, void *buffer, ssize_t size) int ep_num = usb_ep_logical_to_hw(ep); ssize_t max_size = sizeof(rx_buffer); - if (UNLIKELY((size_t)buffer & 0x03)) - { - LOG_ERR("unaligned buffer @ %p\n", buffer); - ASSERT(0); - } - /* Non-blocking read for EP0 */ if (ep_num == CTRL_ENP_OUT) { @@ -1168,12 +1174,6 @@ ssize_t usb_endpointWrite(int ep, const void *buffer, ssize_t size) int ep_num = usb_ep_logical_to_hw(ep); ssize_t max_size = sizeof(tx_buffer); - if (UNLIKELY((size_t)buffer & 0x03)) - { - LOG_ERR("unaligned buffer @ %p\n", buffer); - ASSERT(0); - } - /* Non-blocking write for EP0 */ if (ep_num == CTRL_ENP_IN) { -- 2.25.1