usb: dwc3: Avoid NULL pointer access in dwc3_calc_trbs_left

dwc3_calc_trbs_left function is calling dwc3_ep_prev_trb
which can return NULL if trb pool is empty. This change adds
check for the return value of dwc3_ep_prev_trb function to
avoid NULL pointer dereference.

Change-Id: Id11d5ffd23da7c070d5e0b26842d8738b073b212
Signed-off-by: Pratham Pratap <prathampratap@codeaurora.org>
Signed-off-by: Jack Pham <jackp@codeaurora.org>
This commit is contained in:
Pratham Pratap 2018-03-15 10:31:20 +05:30 • committed by Jack Pham
commit 7972f5f996

View file

@ -1002,7 +1002,7 @@ static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep)
*/
if (dep->trb_enqueue == dep->trb_dequeue) {
tmp = dwc3_ep_prev_trb(dep, dep->trb_enqueue);
if (tmp->ctrl & DWC3_TRB_CTRL_HWO)
if (!tmp || tmp->ctrl & DWC3_TRB_CTRL_HWO)
return 0;
return DWC3_TRB_NUM - 1;