Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: dwc3: gadget: Set speed only up to the max supported

The setting of the device speed should be limited by the device's
maximum_speed. Check and prevent the driver from attempting to configure
higher than the maximum_speed.

Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/4fae4a9ebb60464d64d8b8f6fdfc2777a2206a69.1611106162.git.Thinh.Nguyen@synopsys.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thinh Nguyen and committed by
Greg Kroah-Hartman
450b9e9f f551037c

+10 -5
+10 -5
drivers/usb/dwc3/gadget.c
··· 2064 2064 2065 2065 static void __dwc3_gadget_set_speed(struct dwc3 *dwc) 2066 2066 { 2067 + enum usb_device_speed speed; 2067 2068 u32 reg; 2068 2069 2069 - if (dwc->gadget_max_speed == USB_SPEED_SUPER_PLUS && 2070 + speed = dwc->gadget_max_speed; 2071 + if (speed > dwc->maximum_speed) 2072 + speed = dwc->maximum_speed; 2073 + 2074 + if (speed == USB_SPEED_SUPER_PLUS && 2070 2075 DWC3_IP_IS(DWC32)) { 2071 2076 __dwc3_gadget_set_ssp_rate(dwc); 2072 2077 return; ··· 2097 2092 !dwc->dis_metastability_quirk) { 2098 2093 reg |= DWC3_DCFG_SUPERSPEED; 2099 2094 } else { 2100 - switch (dwc->gadget_max_speed) { 2095 + switch (speed) { 2101 2096 case USB_SPEED_LOW: 2102 2097 reg |= DWC3_DCFG_LOWSPEED; 2103 2098 break; ··· 2117 2112 reg |= DWC3_DCFG_SUPERSPEED_PLUS; 2118 2113 break; 2119 2114 default: 2120 - dev_err(dwc->dev, "invalid speed (%d)\n", dwc->gadget_max_speed); 2115 + dev_err(dwc->dev, "invalid speed (%d)\n", speed); 2121 2116 2122 2117 if (DWC3_IP_IS(DWC3)) 2123 2118 reg |= DWC3_DCFG_SUPERSPEED; ··· 2127 2122 } 2128 2123 2129 2124 if (DWC3_IP_IS(DWC32) && 2130 - dwc->gadget_max_speed > USB_SPEED_UNKNOWN && 2131 - dwc->gadget_max_speed < USB_SPEED_SUPER_PLUS) 2125 + speed > USB_SPEED_UNKNOWN && 2126 + speed < USB_SPEED_SUPER_PLUS) 2132 2127 reg &= ~DWC3_DCFG_NUMLANES(~0); 2133 2128 2134 2129 dwc3_writel(dwc->regs, DWC3_DCFG, reg);