Commit 2b0b0f27efd947d25e130702e8c34a7816076281
Committed by
Sekhar Nori
1 parent
1f28da4920
Exists in
ti-linux-3.14.y
and in
2 other branches
usb: dwc3: gadget: Mark freed EPs as NULL
The freed EPs should be marked as NULL else any further access would cause issues. This was seen while testing suspend/resume with DRD enabled. While at it, check for valid ep0 and ep1 during suspend /resume. ep0 and ep1 are freed while switching from host to device mode. Now that we make it NULL after freeing check the validity during suspend/resume. Signed-off-by: George Cherian <george.cherian@ti.com> [nsekhar@ti.com: minor tweaks to patch description] Signed-off-by: Sekhar Nori <nsekhar@ti.com>
Showing 1 changed file with 26 additions and 20 deletions Side-by-side Diff
drivers/usb/dwc3/gadget.c
... | ... | @@ -1854,6 +1854,7 @@ |
1854 | 1854 | } |
1855 | 1855 | |
1856 | 1856 | kfree(dep); |
1857 | + dwc->eps[epnum] = NULL; | |
1857 | 1858 | } |
1858 | 1859 | } |
1859 | 1860 | |
... | ... | @@ -2957,8 +2958,10 @@ |
2957 | 2958 | dwc->pullups_connected = true; |
2958 | 2959 | } |
2959 | 2960 | |
2960 | - __dwc3_gadget_ep_disable(dwc->eps[0]); | |
2961 | - __dwc3_gadget_ep_disable(dwc->eps[1]); | |
2961 | + if (dwc->eps[0] && dwc->eps[1]) { | |
2962 | + __dwc3_gadget_ep_disable(dwc->eps[0]); | |
2963 | + __dwc3_gadget_ep_disable(dwc->eps[1]); | |
2964 | + } | |
2962 | 2965 | |
2963 | 2966 | dwc->dcfg = dwc3_readl(dwc->regs, DWC3_DCFG); |
2964 | 2967 | |
2965 | 2968 | |
2966 | 2969 | |
2967 | 2970 | |
2968 | 2971 | |
2969 | 2972 | |
2970 | 2973 | |
... | ... | @@ -2970,30 +2973,33 @@ |
2970 | 2973 | struct dwc3_ep *dep; |
2971 | 2974 | int ret; |
2972 | 2975 | |
2973 | - /* Start with SuperSpeed Default */ | |
2974 | - dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); | |
2976 | + if (dwc->eps[0] && dwc->eps[1]) { | |
2977 | + /* Start with SuperSpeed Default */ | |
2978 | + dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); | |
2975 | 2979 | |
2976 | - dep = dwc->eps[0]; | |
2977 | - ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false); | |
2978 | - if (ret) | |
2979 | - goto err0; | |
2980 | + dep = dwc->eps[0]; | |
2981 | + ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, | |
2982 | + NULL, false); | |
2983 | + if (ret) | |
2984 | + goto err0; | |
2980 | 2985 | |
2981 | - dep = dwc->eps[1]; | |
2982 | - ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false); | |
2983 | - if (ret) | |
2984 | - goto err1; | |
2986 | + dep = dwc->eps[1]; | |
2987 | + ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, | |
2988 | + NULL, false); | |
2989 | + if (ret) | |
2990 | + goto err1; | |
2985 | 2991 | |
2986 | - /* begin to receive SETUP packets */ | |
2987 | - dwc->ep0state = EP0_SETUP_PHASE; | |
2988 | - dwc3_ep0_out_start(dwc); | |
2992 | + /* begin to receive SETUP packets */ | |
2993 | + dwc->ep0state = EP0_SETUP_PHASE; | |
2994 | + dwc3_ep0_out_start(dwc); | |
2989 | 2995 | |
2990 | - dwc3_writel(dwc->regs, DWC3_DCFG, dwc->dcfg); | |
2996 | + dwc3_writel(dwc->regs, DWC3_DCFG, dwc->dcfg); | |
2991 | 2997 | |
2992 | - if (dwc->pullups_connected) { | |
2993 | - dwc3_gadget_enable_irq(dwc); | |
2994 | - dwc3_gadget_run_stop(dwc, true, false); | |
2998 | + if (dwc->pullups_connected) { | |
2999 | + dwc3_gadget_enable_irq(dwc); | |
3000 | + dwc3_gadget_run_stop(dwc, true, false); | |
3001 | + } | |
2995 | 3002 | } |
2996 | - | |
2997 | 3003 | return 0; |
2998 | 3004 | |
2999 | 3005 | err1: |