Skip to content

Commit

Permalink
drivers: usb_dc_mcux_ehci: add checks for valid endpoint
Browse files Browse the repository at this point in the history
Add checks for valid endpoint.
Fix controllerHandle check in usb_dc_detach().

Fixes: zephyrproject-rtos#19763

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
  • Loading branch information
jfischer-no committed Feb 13, 2020
1 parent d79b17c commit b88d75a
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion drivers/usb/device/usb_dc_mcux_ehci.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ int usb_dc_detach(void)
{
usb_status_t status;

if (dev_data.controllerHandle != NULL) {
if (dev_data.controllerHandle == NULL) {
LOG_WRN("Device not attached");
return 0;
}
Expand Down Expand Up @@ -317,6 +317,11 @@ int usb_dc_ep_enable(const u8_t ep)
return 0;
}

if (ep_abs_idx >= NUM_OF_EP_MAX) {
LOG_ERR("Wrong endpoint index/address");
return -EINVAL;
}

if (dev_data.eps[ep_abs_idx].ep_occupied) {
LOG_WRN("endpoint 0x%x already enabled", ep);
return -EALREADY;
Expand Down Expand Up @@ -350,6 +355,11 @@ int usb_dc_ep_disable(const u8_t ep)
u8_t ep_abs_idx = EP_ABS_IDX(ep);
usb_status_t status;

if (ep_abs_idx >= NUM_OF_EP_MAX) {
LOG_ERR("Wrong endpoint index/address");
return -EINVAL;
}

status = dev_data.interface->deviceCancel(dev_data.controllerHandle,
ep);
if (kStatus_USB_Success != status) {
Expand Down Expand Up @@ -384,6 +394,11 @@ int usb_dc_ep_write(const u8_t ep, const u8_t *const data,
u32_t len_to_send;
usb_status_t status;

if (ep_abs_idx >= NUM_OF_EP_MAX) {
LOG_ERR("Wrong endpoint index/address");
return -EINVAL;
}

if (data_len > dev_data.eps[ep_abs_idx].ep_mps) {
len_to_send = dev_data.eps[ep_abs_idx].ep_mps;
} else {
Expand Down Expand Up @@ -512,6 +527,11 @@ int usb_dc_ep_read_continue(u8_t ep)
u8_t ep_abs_idx = EP_ABS_IDX(ep);
usb_status_t status;

if (ep_abs_idx >= NUM_OF_EP_MAX) {
LOG_ERR("Wrong endpoint index/address");
return -EINVAL;
}

if (dev_data.eps[ep_abs_idx].ep_occupied) {
LOG_WRN("endpoint 0x%x already occupied", ep);
return -EBUSY;
Expand Down Expand Up @@ -564,6 +584,11 @@ int usb_dc_ep_set_callback(const u8_t ep, const usb_dc_ep_callback cb)
{
u8_t ep_abs_idx = EP_ABS_IDX(ep);

if (ep_abs_idx >= NUM_OF_EP_MAX) {
LOG_ERR("Wrong endpoint index/address");
return -EINVAL;
}

if (!dev_data.attached) {
return -EINVAL;
}
Expand All @@ -581,6 +606,11 @@ int usb_dc_ep_mps(const u8_t ep)
{
u8_t ep_abs_idx = EP_ABS_IDX(ep);

if (ep_abs_idx >= NUM_OF_EP_MAX) {
LOG_ERR("Wrong endpoint index/address");
return -EINVAL;
}

return dev_data.eps[ep_abs_idx].ep_mps;
}

Expand Down

0 comments on commit b88d75a

Please sign in to comment.