@@ -2327,6 +2327,7 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g,
enum usb_device_speed speed)
{
struct dwc3 *dwc = gadget_to_dwc(g);
+ enum usb_device_speed selected_speed = speed;
unsigned long flags;
u32 reg;
@@ -2351,7 +2352,10 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g,
!dwc->dis_metastability_quirk) {
reg |= DWC3_DCFG_SUPERSPEED;
} else {
- switch (speed) {
+ if (speed > dwc->maximum_speed)
+ selected_speed = dwc->maximum_speed;
+
+ switch (selected_speed) {
case USB_SPEED_LOW:
reg |= DWC3_DCFG_LOWSPEED;
break;
@@ -2371,7 +2375,8 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g,
reg |= DWC3_DCFG_SUPERSPEED_PLUS;
break;
default:
- dev_err(dwc->dev, "invalid speed (%d)\n", speed);
+ dev_err(dwc->dev, "invalid speed (%d)\n",
+ selected_speed);
if (DWC3_IP_IS(DWC3))
reg |= DWC3_DCFG_SUPERSPEED;
@@ -2380,7 +2385,7 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g,
}
}
- if (DWC3_IP_IS(DWC32) && speed < USB_SPEED_SUPER_PLUS)
+ if (DWC3_IP_IS(DWC32) && selected_speed < USB_SPEED_SUPER_PLUS)
reg &= ~DWC3_DCFG_NUMLANES(~0);
dwc3_writel(dwc->regs, DWC3_DCFG, reg);
The setting of device speed should be limited by the device's maximum_speed. This patch adds a check and prevent the driver from attempting to configure higher than the maximum_speed. Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com> --- Changes in v5: - Rebase on Felipe's testing/next branch - Changed Signed-off-by email to match From: email header Changes in v4: - None Changes in v3: - None Changes in v2: - None drivers/usb/dwc3/gadget.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)