diff options
author | Jack Pham <jackp@codeaurora.org> | 2014-03-26 13:31:44 -0400 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2014-04-16 11:11:45 -0400 |
commit | 32702e96a9f76ea0e0a1d218310d2ac1adbd2907 (patch) | |
tree | 46d152d4f7e1f9bb96020e1f8b9e909f81f56cb3 | |
parent | 8b2bc2c9351b4c09bc3d9096e2a7af3988565dbf (diff) |
usb: dwc3: gadget: Iterate only over valid endpoints
Make dwc3_gadget_resize_tx_fifos() iterate only over IN
endpoints that are actually present, based on the
num_in_eps parameter. This terminates the loop so as to
prevent dereferencing a potential NULL dwc->eps[i] where
i >= (num_in_eps + num_out_eps).
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r-- | drivers/usb/dwc3/gadget.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index a740eac74d56..70715eeededd 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c | |||
@@ -187,15 +187,12 @@ int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc) | |||
187 | * improve this algorithm so that we better use the internal | 187 | * improve this algorithm so that we better use the internal |
188 | * FIFO space | 188 | * FIFO space |
189 | */ | 189 | */ |
190 | for (num = 0; num < DWC3_ENDPOINTS_NUM; num++) { | 190 | for (num = 0; num < dwc->num_in_eps; num++) { |
191 | struct dwc3_ep *dep = dwc->eps[num]; | 191 | /* bit0 indicates direction; 1 means IN ep */ |
192 | int fifo_number = dep->number >> 1; | 192 | struct dwc3_ep *dep = dwc->eps[(num << 1) | 1]; |
193 | int mult = 1; | 193 | int mult = 1; |
194 | int tmp; | 194 | int tmp; |
195 | 195 | ||
196 | if (!(dep->number & 1)) | ||
197 | continue; | ||
198 | |||
199 | if (!(dep->flags & DWC3_EP_ENABLED)) | 196 | if (!(dep->flags & DWC3_EP_ENABLED)) |
200 | continue; | 197 | continue; |
201 | 198 | ||
@@ -224,8 +221,7 @@ int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc) | |||
224 | dev_vdbg(dwc->dev, "%s: Fifo Addr %04x Size %d\n", | 221 | dev_vdbg(dwc->dev, "%s: Fifo Addr %04x Size %d\n", |
225 | dep->name, last_fifo_depth, fifo_size & 0xffff); | 222 | dep->name, last_fifo_depth, fifo_size & 0xffff); |
226 | 223 | ||
227 | dwc3_writel(dwc->regs, DWC3_GTXFIFOSIZ(fifo_number), | 224 | dwc3_writel(dwc->regs, DWC3_GTXFIFOSIZ(num), fifo_size); |
228 | fifo_size); | ||
229 | 225 | ||
230 | last_fifo_depth += (fifo_size & 0xffff); | 226 | last_fifo_depth += (fifo_size & 0xffff); |
231 | } | 227 | } |