diff mbox series

[RFC,09/14] usb: dwc3: gadget: Limit the setting of speed

Message ID dd7817eaa55d28642f9fbc9276e4637dbffe8b2b.1576118671.git.thinhn@synopsys.com (mailing list archive)
State New, archived
Headers show
Series usb: dwc3: Introduce DWC_usb32 | expand

Commit Message

Thinh Nguyen Dec. 12, 2019, 2:49 a.m. UTC
The setting of device speed should be limited by the device property
maximum_speed. This patch adds a check and limit that setting.

Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
---
 drivers/usb/dwc3/gadget.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 06325e269234..d56feea01066 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2126,6 +2126,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	allowable_speed = speed;
 	unsigned long		flags;
 	u32			reg;
 
@@ -2150,7 +2151,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)
+			allowable_speed = dwc->maximum_speed;
+
+		switch (allowable_speed) {
 		case USB_SPEED_LOW:
 			reg |= DWC3_DCFG_LOWSPEED;
 			break;
@@ -2170,7 +2174,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",
+				allowable_speed);
 
 			if (dwc3_is_usb3(dwc))
 				reg |= DWC3_DCFG_SUPERSPEED;