835ea17335ccdf981c40502daa81c5a5a2c684a9
[openwrt/svn-archive/archive.git] / target / linux / brcm2708 / patches-3.10 / 0083-dwc_otg-prevent-BUG-in-TT-allocation-if-hub-address-.patch
1 From 14d8b16453f653003fd7d124f221082c53d56cf2 Mon Sep 17 00:00:00 2001
2 From: P33M <P33M@github.com>
3 Date: Mon, 22 Jul 2013 14:08:26 +0100
4 Subject: [PATCH 083/196] dwc_otg: prevent BUG() in TT allocation if hub
5 address is > 16
6
7 A fixed-size array is used to track TT allocation. This was
8 previously set to 16 which caused a crash because
9 dwc_otg_hcd_allocate_port would read past the end of the array.
10
11 This was hit if a hub was plugged in which enumerated as addr > 16,
12 due to previous device resets or unplugs.
13
14 Also add #ifdef FIQ_DEBUG around hcd->hub_port_alloc[], which grows
15 to a large size if 128 hub addresses are supported. This field is
16 for debug only for tracking which frame an allocate happened in.
17 ---
18 drivers/usb/host/dwc_otg/dwc_otg_hcd.c | 7 ++++++-
19 drivers/usb/host/dwc_otg/dwc_otg_hcd.h | 6 ++++--
20 drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c | 3 ++-
21 3 files changed, 12 insertions(+), 4 deletions(-)
22
23 diff --git a/drivers/usb/host/dwc_otg/dwc_otg_hcd.c b/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
24 index a1970dc..3c619b4 100644
25 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
26 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
27 @@ -983,7 +983,9 @@ int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
28 hcd->periodic_qh_count = 0;
29
30 DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
31 +#ifdef FIQ_DEBUG
32 DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
33 +#endif
34
35 out:
36 return retval;
37 @@ -1317,7 +1319,9 @@ int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
38 qh->skip_count = 0;
39 hcd->hub_port[hub_addr] |= 1 << port_addr;
40 fiq_print(FIQDBG_PORTHUB, "H%dP%d:A %d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
41 +#ifdef FIQ_DEBUG
42 hcd->hub_port_alloc[hub_addr * 16 + port_addr] = dwc_otg_hcd_get_frame_number(hcd);
43 +#endif
44 return 0;
45 }
46 }
47 @@ -1331,8 +1335,9 @@ void dwc_otg_hcd_release_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
48 hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
49
50 hcd->hub_port[hub_addr] &= ~(1 << port_addr);
51 +#ifdef FIQ_DEBUG
52 hcd->hub_port_alloc[hub_addr * 16 + port_addr] = -1;
53 -
54 +#endif
55 fiq_print(FIQDBG_PORTHUB, "H%dP%d:RO%d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
56
57 }
58 diff --git a/drivers/usb/host/dwc_otg/dwc_otg_hcd.h b/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
59 index d3d6e997..80a3af2 100644
60 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
61 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
62 @@ -577,8 +577,10 @@ struct dwc_otg_hcd {
63 uint32_t *frame_list;
64
65 /** Hub - Port assignment */
66 - int hub_port[16];
67 - int hub_port_alloc[256];
68 + int hub_port[128];
69 +#ifdef FIQ_DEBUG
70 + int hub_port_alloc[2048];
71 +#endif
72
73 /** Frame List DMA address */
74 dma_addr_t frame_list_dma;
75 diff --git a/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c b/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
76 index 765451b..dbff763 100644
77 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
78 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
79 @@ -1419,8 +1419,9 @@ cleanup:
80 }
81
82 hcd->hub_port[hc->hub_addr] &= ~(1 << hc->port_addr);
83 +#ifdef FIQ_DEBUG
84 hcd->hub_port_alloc[hc->hub_addr * 16 + hc->port_addr] = -1;
85 -
86 +#endif
87 fiq_print(FIQDBG_PORTHUB, "H%dP%d:RR%d", hc->hub_addr, hc->port_addr, endp);
88 }
89
90 --
91 1.9.1
92