Skip to content

Commit 38ab6f5

Browse files
committed
update(port): add USB_ASSERT_MSG for ep num check
Signed-off-by: sakumisu <[email protected]>
1 parent 8393ed9 commit 38ab6f5

File tree

5 files changed

+15
-31
lines changed

5 files changed

+15
-31
lines changed

port/chipidea/usb_dc_chipidea.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,7 @@ int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
525525
{
526526
uint8_t ep_idx = USB_EP_GET_IDX(ep->bEndpointAddress);
527527

528-
/* Must not exceed max endpoint number */
529-
if (ep_idx >= CONFIG_USBDEV_EP_NUM) {
530-
return -1;
531-
}
528+
USB_ASSERT_MSG(ep_idx < CONFIG_USBDEV_EP_NUM, "Ep addr %02x overflow", ep->bEndpointAddress);
532529

533530
chipidea_edpt_open(busid, ep->bEndpointAddress, USB_GET_ENDPOINT_TYPE(ep->bmAttributes), ep->wMaxPacketSize);
534531

@@ -666,17 +663,10 @@ void USBD_IRQHandler(uint8_t busid)
666663

667664
if (int_status & intr_usb) {
668665
uint32_t const edpt_complete = USB_OTG_DEV->ENDPTCOMPLETE;
669-
USB_OTG_DEV->ENDPTCOMPLETE = edpt_complete;
670666
uint32_t edpt_setup_status = USB_OTG_DEV->ENDPTSETUPSTAT;
671667

672-
if (edpt_setup_status) {
673-
/*------------- Set up Received -------------*/
674-
USB_OTG_DEV->ENDPTSETUPSTAT = edpt_setup_status;
675-
dcd_qhd_t *qhd0 = chipidea_qhd_get(busid, 0);
676-
usbd_event_ep0_setup_complete_handler(busid, (uint8_t *)&qhd0->setup_request);
677-
}
678-
679668
if (edpt_complete) {
669+
USB_OTG_DEV->ENDPTCOMPLETE = edpt_complete;
680670
for (uint8_t ep_idx = 0; ep_idx < (CONFIG_USBDEV_EP_NUM * 2); ep_idx++) {
681671
if (edpt_complete & (1 << ep_idx2bit(ep_idx))) {
682672
transfer_len = 0;
@@ -714,5 +704,12 @@ void USBD_IRQHandler(uint8_t busid)
714704
}
715705
}
716706
}
707+
708+
if (edpt_setup_status) {
709+
/*------------- Set up Received -------------*/
710+
USB_OTG_DEV->ENDPTSETUPSTAT = edpt_setup_status;
711+
dcd_qhd_t *qhd0 = chipidea_qhd_get(busid, 0);
712+
usbd_event_ep0_setup_complete_handler(busid, (uint8_t *)&qhd0->setup_request);
713+
}
717714
}
718715
}

port/dwc2/usb_dc_dwc2.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -711,10 +711,7 @@ int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
711711
{
712712
uint8_t ep_idx = USB_EP_GET_IDX(ep->bEndpointAddress);
713713

714-
if (ep_idx > (CONFIG_USBDEV_EP_NUM - 1)) {
715-
USB_LOG_ERR("Ep addr %02x overflow\r\n", ep->bEndpointAddress);
716-
return -1;
717-
}
714+
USB_ASSERT_MSG(ep_idx < CONFIG_USBDEV_EP_NUM, "Ep addr %02x overflow", ep->bEndpointAddress);
718715

719716
if (USB_EP_DIR_IS_OUT(ep->bEndpointAddress)) {
720717
g_dwc2_udc[busid].out_ep[ep_idx].ep_mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
@@ -735,10 +732,8 @@ int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
735732
} else {
736733
fifo_size = (USB_OTG_GLB->DIEPTXF[ep_idx - 1U] >> 16);
737734
}
738-
if ((fifo_size * 4) < USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize)) {
739-
USB_LOG_ERR("Ep addr %02x fifo overflow\r\n", ep->bEndpointAddress);
740-
return -2;
741-
}
735+
736+
USB_ASSERT_MSG((fifo_size * 4) >= USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize), "Ep addr %02x fifo overflow", ep->bEndpointAddress);
742737

743738
g_dwc2_udc[busid].in_ep[ep_idx].ep_mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
744739
g_dwc2_udc[busid].in_ep[ep_idx].ep_type = USB_GET_ENDPOINT_TYPE(ep->bmAttributes);

port/fsdev/usb_dc_fsdev.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
131131
{
132132
uint8_t ep_idx = USB_EP_GET_IDX(ep->bEndpointAddress);
133133

134-
if (ep_idx > (CONFIG_USBDEV_EP_NUM - 1)) {
135-
USB_LOG_ERR("Ep addr %02x overflow\r\n", ep->bEndpointAddress);
136-
return -1;
137-
}
134+
USB_ASSERT_MSG(ep_idx < CONFIG_USBDEV_EP_NUM, "Ep addr %02x overflow", ep->bEndpointAddress);
138135

139136
uint16_t wEpRegVal;
140137

port/kinetis/usb_dc_kinetis.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
156156
uint8_t regval;
157157

158158
/* Must not exceed max endpoint number */
159-
if (ep_idx >= CONFIG_USBDEV_EP_NUM) {
160-
return -1;
161-
}
159+
USB_ASSERT_MSG(ep_idx < CONFIG_USBDEV_EP_NUM, "Ep addr %02x overflow", ep->bEndpointAddress);
162160

163161
if (USB_EP_DIR_IS_OUT(ep->bEndpointAddress)) {
164162
g_kinetis_udc[busid].out_ep[ep_idx].ep_mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);

port/musb/usb_dc_musb.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,7 @@ int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
331331
return 0;
332332
}
333333

334-
if (ep_idx > (CONFIG_USBDEV_EP_NUM - 1)) {
335-
USB_LOG_ERR("Ep addr %02x overflow\r\n", ep->bEndpointAddress);
336-
return -1;
337-
}
334+
USB_ASSERT_MSG(ep_idx < CONFIG_USBDEV_EP_NUM, "Ep addr %02x overflow", ep->bEndpointAddress);
338335

339336
old_ep_idx = musb_get_active_ep();
340337
musb_set_active_ep(ep_idx);

0 commit comments

Comments
 (0)