Skip to content
Permalink
Browse files

usb: usb_dc_native_posix: Fix valid endpoints check

Fix check for valid endpoints; issue is found in harness testing.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
  • Loading branch information...
finikorg authored and nashif committed Mar 26, 2019
1 parent 23d2204 commit 81fbf0f4b57ab65b37d5c01caff4ecf73ed4ef4c
Showing with 24 additions and 14 deletions.
  1. +24 −14 drivers/usb/device/usb_dc_native_posix.c
@@ -196,7 +196,8 @@ int usb_dc_ep_configure(const struct usb_dc_ep_cfg_data * const cfg)
return -EINVAL;
}

if (!usbip_ctrl.attached && !usbip_ep_is_valid(ep)) {
if (!usbip_ctrl.attached || !usbip_ep_is_valid(ep)) {
LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep);
return -EINVAL;
}

@@ -213,7 +214,8 @@ int usb_dc_ep_set_stall(const u8_t ep)
{
LOG_DBG("ep %x", ep);

if (!usbip_ctrl.attached && !usbip_ep_is_valid(ep)) {
if (!usbip_ctrl.attached || !usbip_ep_is_valid(ep)) {
LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep);
return -EINVAL;
}

@@ -229,7 +231,8 @@ int usb_dc_ep_clear_stall(const u8_t ep)

LOG_DBG("ep %x", ep);

if (!usbip_ctrl.attached && !usbip_ep_is_valid(ep)) {
if (!usbip_ctrl.attached || !usbip_ep_is_valid(ep)) {
LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep);
return -EINVAL;
}

@@ -247,7 +250,8 @@ int usb_dc_ep_halt(const u8_t ep)

LOG_DBG("ep %x", ep);

if (!usbip_ctrl.attached && !usbip_ep_is_valid(ep)) {
if (!usbip_ctrl.attached || !usbip_ep_is_valid(ep)) {
LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep);
return -EINVAL;
}

@@ -263,7 +267,8 @@ int usb_dc_ep_is_stalled(const u8_t ep, u8_t *const stalled)
{
LOG_DBG("ep %x", ep);

if (!usbip_ctrl.attached && !usbip_ep_is_valid(ep)) {
if (!usbip_ctrl.attached || !usbip_ep_is_valid(ep)) {
LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep);
return -EINVAL;
}

@@ -280,7 +285,8 @@ int usb_dc_ep_enable(const u8_t ep)

LOG_DBG("ep %x", ep);

if (!usbip_ctrl.attached && !usbip_ep_is_valid(ep)) {
if (!usbip_ctrl.attached || !usbip_ep_is_valid(ep)) {
LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep);
return -EINVAL;
}

@@ -305,7 +311,8 @@ int usb_dc_ep_flush(const u8_t ep)
{
LOG_DBG("ep %x", ep);

if (!usbip_ctrl.attached && !usbip_ep_is_valid(ep)) {
if (!usbip_ctrl.attached || !usbip_ep_is_valid(ep)) {
LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep);
return -EINVAL;
}

@@ -322,7 +329,8 @@ int usb_dc_ep_write(const u8_t ep, const u8_t *const data,
{
LOG_DBG("ep %x len %u", ep, data_len);

if (!usbip_ctrl.attached && !usbip_ep_is_valid(ep)) {
if (!usbip_ctrl.attached || !usbip_ep_is_valid(ep)) {
LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep);
return -EINVAL;
}

@@ -360,8 +368,8 @@ int usb_dc_ep_read_wait(u8_t ep, u8_t *data, u32_t max_data_len,
{
u32_t bytes;

if (!usbip_ctrl.attached && !usbip_ep_is_valid(ep)) {
LOG_ERR("No valid endpoint");
if (!usbip_ctrl.attached || !usbip_ep_is_valid(ep)) {
LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep);
return -EINVAL;
}

@@ -398,8 +406,8 @@ int usb_dc_ep_read_continue(u8_t ep)
{
u8_t ep_idx = USBIP_EP_ADDR2IDX(ep);

if (!usbip_ctrl.attached && !usbip_ep_is_valid(ep)) {
LOG_ERR("No valid endpoint");
if (!usbip_ctrl.attached || !usbip_ep_is_valid(ep)) {
LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep);
return -EINVAL;
}

@@ -446,7 +454,8 @@ int usb_dc_ep_set_callback(const u8_t ep, const usb_dc_ep_callback cb)

LOG_DBG("ep %x callback %p", ep, cb);

if (!usbip_ctrl.attached && !usbip_ep_is_valid(ep)) {
if (!usbip_ctrl.attached || !usbip_ep_is_valid(ep)) {
LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep);
return -EINVAL;
}

@@ -472,7 +481,8 @@ int usb_dc_ep_mps(const u8_t ep)

LOG_DBG("ep %x", ep);

if (!usbip_ep_is_valid(ep)) {
if (!usbip_ctrl.attached || !usbip_ep_is_valid(ep)) {
LOG_ERR("Not attached / Invalid endpoint: EP 0x%x", ep);
return -EINVAL;
}

0 comments on commit 81fbf0f

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