drivers: usb_dc_mcux_ehci: add checks for valid endpoint
Add checks for valid endpoint. Fix controllerHandle check in usb_dc_detach(). Fixes: #19763 Signed-off-by: Johann Fischer <j.fischer@phytec.de>
This commit is contained in:
parent
e9a35dd6f1
commit
e0b2227c39
1 changed files with 31 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue