Skip to content
Permalink
Browse files

usb_dc_stm32: Check if functions' arguments are valid

Check if usb_dc_* functions' arguments are valid.
Fixes `tests/subsys/usb/device` on STM32 SoCs.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
  • Loading branch information...
ydamigos authored and nashif committed May 18, 2019
1 parent d548105 commit a1e3f3921498edaeb161cdb97e990910212c9acb
Showing with 14 additions and 4 deletions.
  1. +14 −4 drivers/usb/device/usb_dc_stm32.c
@@ -533,7 +533,7 @@ int usb_dc_ep_start_read(u8_t ep, u8_t *data, u32_t max_data_len)

int usb_dc_ep_get_read_count(u8_t ep, u32_t *read_bytes)
{
if (!EP_IS_OUT(ep)) {
if (!EP_IS_OUT(ep) || !read_bytes) {
LOG_ERR("invalid ep 0x%02x", ep);
return -EINVAL;
}
@@ -659,7 +659,7 @@ int usb_dc_ep_is_stalled(const u8_t ep, u8_t *const stalled)

LOG_DBG("ep 0x%02x", ep);

if (!ep_state) {
if (!ep_state || !stalled) {
return -EINVAL;
}

@@ -730,7 +730,7 @@ int usb_dc_ep_write(const u8_t ep, const u8_t *const data,

LOG_DBG("ep 0x%02x, len %u", ep, data_len);

if (!EP_IS_IN(ep)) {
if (!ep_state || !EP_IS_IN(ep)) {
LOG_ERR("invalid ep 0x%02x", ep);
return -EINVAL;
}
@@ -822,7 +822,7 @@ int usb_dc_ep_read_continue(u8_t ep)
{
struct usb_dc_stm32_ep_state *ep_state = usb_dc_stm32_get_ep_state(ep);

if (!EP_IS_OUT(ep)) { /* Check if OUT ep */
if (!ep_state || !EP_IS_OUT(ep)) { /* Check if OUT ep */
LOG_ERR("Not valid endpoint: %02x", ep);
return -EINVAL;
}
@@ -859,6 +859,12 @@ int usb_dc_ep_halt(const u8_t ep)

int usb_dc_ep_flush(const u8_t ep)
{
struct usb_dc_stm32_ep_state *ep_state = usb_dc_stm32_get_ep_state(ep);

if (!ep_state) {
return -EINVAL;
}

LOG_ERR("Not implemented");

return 0;
@@ -868,6 +874,10 @@ int usb_dc_ep_mps(const u8_t ep)
{
struct usb_dc_stm32_ep_state *ep_state = usb_dc_stm32_get_ep_state(ep);

if (!ep_state) {
return -EINVAL;
}

return ep_state->ep_mps;
}

0 comments on commit a1e3f39

Please sign in to comment.
You can’t perform that action at this time.