ipq806x: switch to upstream usb driver and backport fixes
[oweals/openwrt.git] / target / linux / ipq806x / patches-4.4 / 096-03-usb-dwc3-Validate-the-maximum_speed-parameter.patch
1 From 77966eb85e6d988a6daaf8ac14ac33026ceb3ab7 Mon Sep 17 00:00:00 2001
2 From: John Youn <John.Youn@synopsys.com>
3 Date: Fri, 19 Feb 2016 17:31:01 -0800
4 Subject: usb: dwc3: Validate the maximum_speed parameter
5
6 Check that dwc->maximum_speed is set to a valid value. Also add an error
7 when we use it later if we encounter an invalid value.
8
9 Signed-off-by: John Youn <johnyoun@synopsys.com>
10 Signed-off-by: Felipe Balbi <balbi@kernel.org>
11 ---
12  drivers/usb/dwc3/core.c   | 18 ++++++++++++++++--
13  drivers/usb/dwc3/gadget.c |  9 ++++++---
14  2 files changed, 22 insertions(+), 5 deletions(-)
15
16 diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
17 index 001c755..17fd814 100644
18 --- a/drivers/usb/dwc3/core.c
19 +++ b/drivers/usb/dwc3/core.c
20 @@ -1012,8 +1012,20 @@ static int dwc3_probe(struct platform_device *pdev)
21                 goto err1;
22         }
23  
24 -       /* default to superspeed if no maximum_speed passed */
25 -       if (dwc->maximum_speed == USB_SPEED_UNKNOWN) {
26 +       /* Check the maximum_speed parameter */
27 +       switch (dwc->maximum_speed) {
28 +       case USB_SPEED_LOW:
29 +       case USB_SPEED_FULL:
30 +       case USB_SPEED_HIGH:
31 +       case USB_SPEED_SUPER:
32 +       case USB_SPEED_SUPER_PLUS:
33 +               break;
34 +       default:
35 +               dev_err(dev, "invalid maximum_speed parameter %d\n",
36 +                       dwc->maximum_speed);
37 +               /* fall through */
38 +       case USB_SPEED_UNKNOWN:
39 +               /* default to superspeed */
40                 dwc->maximum_speed = USB_SPEED_SUPER;
41  
42                 /*
43 @@ -1023,6 +1035,8 @@ static int dwc3_probe(struct platform_device *pdev)
44                     (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
45                      DWC3_GHWPARAMS3_SSPHY_IFC_GEN2))
46                         dwc->maximum_speed = USB_SPEED_SUPER_PLUS;
47 +
48 +               break;
49         }
50  
51         /* Adjust Frame Length */
52 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
53 index 482e6a1..3ac170f 100644
54 --- a/drivers/usb/dwc3/gadget.c
55 +++ b/drivers/usb/dwc3/gadget.c
56 @@ -1670,10 +1670,13 @@ static int dwc3_gadget_start(struct usb_gadget *g,
57                 case USB_SPEED_SUPER_PLUS:
58                         reg |= DWC3_DSTS_SUPERSPEED_PLUS;
59                         break;
60 -               case USB_SPEED_SUPER:   /* FALLTHROUGH */
61 -               case USB_SPEED_UNKNOWN: /* FALTHROUGH */
62                 default:
63 -                       reg |= DWC3_DSTS_SUPERSPEED;
64 +                       dev_err(dwc->dev, "invalid dwc->maximum_speed (%d)\n",
65 +                               dwc->maximum_speed);
66 +                       /* fall through */
67 +               case USB_SPEED_SUPER:
68 +                       reg |= DWC3_DCFG_SUPERSPEED;
69 +                       break;
70                 }
71         }
72         dwc3_writel(dwc->regs, DWC3_DCFG, reg);
73 -- 
74 cgit v0.12