Skip to content
Permalink
Browse files

drivers: usb_dc_nrfx: Add pre-transfer checks if endpoint is enabled

The shim didn't check if a given endpoint was enabled before requesting
the nrfx_usbd driver to perform a read or write operation on it.
In certain circumstances this led to nrfx_usbd driver being stuck in
a loop waiting for the associated DMA transfer to complete.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
  • Loading branch information...
anangl authored and carlescufi committed Jun 26, 2019
1 parent 1b3514a commit 6e75d644de41ed4f9d5b693921aef0595870cd85
Showing with 14 additions and 0 deletions.
  1. +14 −0 drivers/usb/device/usb_dc_nrfx.c
@@ -1640,6 +1640,10 @@ int usb_dc_ep_write(const u8_t ep, const u8_t *const data,
return -EINVAL;
}

if (!ep_ctx->cfg.en) {
LOG_ERR("Endpoint 0x%02x is not enabled", ep);
return -EINVAL;
}

k_mutex_lock(&ctx->drv_lock, K_FOREVER);

@@ -1723,6 +1727,11 @@ int usb_dc_ep_read_wait(u8_t ep, u8_t *data, u32_t max_data_len,
return -EINVAL;
}

if (!ep_ctx->cfg.en) {
LOG_ERR("Endpoint 0x%02x is not enabled", ep);
return -EINVAL;
}

k_mutex_lock(&ctx->drv_lock, K_FOREVER);

bytes_to_copy = MIN(max_data_len, ep_ctx->buf.len);
@@ -1765,6 +1774,11 @@ int usb_dc_ep_read_continue(u8_t ep)
return -EINVAL;
}

if (!ep_ctx->cfg.en) {
LOG_ERR("Endpoint 0x%02x is not enabled", ep);
return -EINVAL;
}

k_mutex_lock(&ctx->drv_lock, K_FOREVER);
if (!ep_ctx->buf.len) {
ep_ctx->buf.curr = ep_ctx->buf.data;

0 comments on commit 6e75d64

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