Skip to content

Commit 28d5c20

Browse files
P33MP33M
P33M
authored and
P33M
committed
dwc_otg: prevent BUG() in TT allocation if hub address is > 16
A fixed-size array is used to track TT allocation. This was previously set to 16 which caused a crash because dwc_otg_hcd_allocate_port would read past the end of the array. This was hit if a hub was plugged in which enumerated as addr > 16, due to previous device resets or unplugs. Also add #ifdef FIQ_DEBUG around hcd->hub_port_alloc[], which grows to a large size if 128 hub addresses are supported. This field is for debug only for tracking which frame an allocate happened in.
1 parent eb1b482 commit 28d5c20

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

drivers/usb/host/dwc_otg/dwc_otg_hcd.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,9 @@ int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
983983
hcd->periodic_qh_count = 0;
984984

985985
DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
986+
#ifdef FIQ_DEBUG
986987
DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
988+
#endif
987989

988990
out:
989991
return retval;
@@ -1317,7 +1319,9 @@ int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
13171319
qh->skip_count = 0;
13181320
hcd->hub_port[hub_addr] |= 1 << port_addr;
13191321
fiq_print(FIQDBG_PORTHUB, "H%dP%d:A %d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
1322+
#ifdef FIQ_DEBUG
13201323
hcd->hub_port_alloc[hub_addr * 16 + port_addr] = dwc_otg_hcd_get_frame_number(hcd);
1324+
#endif
13211325
return 0;
13221326
}
13231327
}
@@ -1331,8 +1335,9 @@ void dwc_otg_hcd_release_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
13311335
hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
13321336

13331337
hcd->hub_port[hub_addr] &= ~(1 << port_addr);
1338+
#ifdef FIQ_DEBUG
13341339
hcd->hub_port_alloc[hub_addr * 16 + port_addr] = -1;
1335-
1340+
#endif
13361341
fiq_print(FIQDBG_PORTHUB, "H%dP%d:RO%d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
13371342

13381343
}

drivers/usb/host/dwc_otg/dwc_otg_hcd.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,10 @@ struct dwc_otg_hcd {
577577
uint32_t *frame_list;
578578

579579
/** Hub - Port assignment */
580-
int hub_port[16];
581-
int hub_port_alloc[256];
580+
int hub_port[128];
581+
#ifdef FIQ_DEBUG
582+
int hub_port_alloc[2048];
583+
#endif
582584

583585
/** Frame List DMA address */
584586
dma_addr_t frame_list_dma;

drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,8 +1419,9 @@ static void release_channel(dwc_otg_hcd_t * hcd,
14191419
}
14201420

14211421
hcd->hub_port[hc->hub_addr] &= ~(1 << hc->port_addr);
1422+
#ifdef FIQ_DEBUG
14221423
hcd->hub_port_alloc[hc->hub_addr * 16 + hc->port_addr] = -1;
1423-
1424+
#endif
14241425
fiq_print(FIQDBG_PORTHUB, "H%dP%d:RR%d", hc->hub_addr, hc->port_addr, endp);
14251426
}
14261427

0 commit comments

Comments
 (0)