From 1fa988d13591d8fa9b4a2df46a936aa30eff73bb Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Fri, 10 Mar 2023 07:54:49 +0100 Subject: [PATCH] sys/usbus: handle exceeding of number of endpoints If the number of endpoints is not sufficient for an application, it should not be silently ignored and cause a non-working application. Rather, should cause an assertion as it is a configuration issue. --- sys/usb/usbus/cdc/acm/cdc_acm.c | 3 +++ sys/usb/usbus/cdc/ecm/cdc_ecm.c | 3 +++ sys/usb/usbus/hid/hid.c | 2 ++ sys/usb/usbus/msc/msc.c | 2 ++ 4 files changed, 10 insertions(+) diff --git a/sys/usb/usbus/cdc/acm/cdc_acm.c b/sys/usb/usbus/cdc/acm/cdc_acm.c index 9fadb34e80..77c93bcb5a 100644 --- a/sys/usb/usbus/cdc/acm/cdc_acm.c +++ b/sys/usb/usbus/cdc/acm/cdc_acm.c @@ -231,18 +231,21 @@ static void _init(usbus_t *usbus, usbus_handler_t *handler) usbus_endpoint_t *ep = usbus_add_endpoint(usbus, &cdcacm->iface_ctrl, USB_EP_TYPE_INTERRUPT, USB_EP_DIR_IN, 8); + assert(ep); ep->interval = 255; /* Max interval */ usbus_enable_endpoint(ep); ep = usbus_add_endpoint(usbus, &cdcacm->iface_data, USB_EP_TYPE_BULK, USB_EP_DIR_IN, CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE); ep->interval = 0; /* Interval is not used with bulk endpoints */ + assert(ep); usbus_enable_endpoint(ep); /* Store the endpoint reference to activate it * when DTE present is signalled by the host */ ep = usbus_add_endpoint(usbus, &cdcacm->iface_data, USB_EP_TYPE_BULK, USB_EP_DIR_OUT, CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE); + assert(ep); ep->interval = 0; /* Interval is not used with bulk endpoints */ usbus_enable_endpoint(ep); diff --git a/sys/usb/usbus/cdc/ecm/cdc_ecm.c b/sys/usb/usbus/cdc/ecm/cdc_ecm.c index e9374add80..7fa4f8cd8f 100644 --- a/sys/usb/usbus/cdc/ecm/cdc_ecm.c +++ b/sys/usb/usbus/cdc/ecm/cdc_ecm.c @@ -218,6 +218,7 @@ static void _init(usbus_t *usbus, usbus_handler_t *handler) USB_EP_TYPE_INTERRUPT, USB_EP_DIR_IN, USBUS_CDCECM_EP_CTRL_SIZE); + assert(cdcecm->ep_ctrl); cdcecm->ep_ctrl->interval = 0x10; cdcecm->ep_out = usbus_add_endpoint(usbus, @@ -225,12 +226,14 @@ static void _init(usbus_t *usbus, usbus_handler_t *handler) USB_EP_TYPE_BULK, USB_EP_DIR_OUT, USBUS_CDCECM_EP_DATA_SIZE); + assert(cdcecm->ep_out); cdcecm->ep_out->interval = 0; /* Must be 0 for bulk endpoints */ cdcecm->ep_in = usbus_add_endpoint(usbus, (usbus_interface_t *)&cdcecm->iface_data_alt, USB_EP_TYPE_BULK, USB_EP_DIR_IN, USBUS_CDCECM_EP_DATA_SIZE); + assert(cdcecm->ep_in); cdcecm->ep_in->interval = 0; /* Must be 0 for bulk endpoints */ /* Add interfaces to the stack */ diff --git a/sys/usb/usbus/hid/hid.c b/sys/usb/usbus/hid/hid.c index 40f5ed5092..caadde9034 100644 --- a/sys/usb/usbus/hid/hid.c +++ b/sys/usb/usbus/hid/hid.c @@ -121,6 +121,7 @@ static void _init(usbus_t *usbus, usbus_handler_t *handler) USB_EP_TYPE_INTERRUPT, USB_EP_DIR_IN, CONFIG_USBUS_HID_INTERRUPT_EP_SIZE); + assert(hid->ep_in); /* interrupt endpoint polling rate in ms */ hid->ep_in->interval = 0x05; @@ -131,6 +132,7 @@ static void _init(usbus_t *usbus, usbus_handler_t *handler) hid->ep_out = usbus_add_endpoint(usbus, &hid->iface, USB_EP_TYPE_INTERRUPT, USB_EP_DIR_OUT, CONFIG_USBUS_HID_INTERRUPT_EP_SIZE); + assert(hid->ep_out); /* interrupt endpoint polling rate in ms */ hid->ep_out->interval = 0x05; diff --git a/sys/usb/usbus/msc/msc.c b/sys/usb/usbus/msc/msc.c index aa185988d7..30e508271b 100644 --- a/sys/usb/usbus/msc/msc.c +++ b/sys/usb/usbus/msc/msc.c @@ -339,9 +339,11 @@ static void _init(usbus_t *usbus, usbus_handler_t *handler) /* Create required endpoints */ msc->ep_in = usbus_add_endpoint(usbus, &msc->iface, USB_EP_TYPE_BULK, USB_EP_DIR_IN, CONFIG_USBUS_EP0_SIZE); + assert(msc->ep_in); msc->ep_in->interval = 0; msc->ep_out = usbus_add_endpoint(usbus, &msc->iface, USB_EP_TYPE_BULK, USB_EP_DIR_OUT, CONFIG_USBUS_EP0_SIZE); + assert(msc->ep_out); msc->ep_out->interval = 0; /* Add interfaces to the stack */