096-03-usb-dwc3-Validate-the-maximum_speed-parameter.patch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. Check that dwc->maximum_speed is set to a valid value. Also add an error
  6. when we use it later if we encounter an invalid value.
  7. Signed-off-by: John Youn <johnyoun@synopsys.com>
  8. Signed-off-by: Felipe Balbi <balbi@kernel.org>
  9. ---
  10. drivers/usb/dwc3/core.c | 18 ++++++++++++++++--
  11. drivers/usb/dwc3/gadget.c | 9 ++++++---
  12. 2 files changed, 22 insertions(+), 5 deletions(-)
  13. --- a/drivers/usb/dwc3/core.c
  14. +++ b/drivers/usb/dwc3/core.c
  15. @@ -1012,8 +1012,20 @@ static int dwc3_probe(struct platform_de
  16. goto err1;
  17. }
  18. - /* default to superspeed if no maximum_speed passed */
  19. - if (dwc->maximum_speed == USB_SPEED_UNKNOWN) {
  20. + /* Check the maximum_speed parameter */
  21. + switch (dwc->maximum_speed) {
  22. + case USB_SPEED_LOW:
  23. + case USB_SPEED_FULL:
  24. + case USB_SPEED_HIGH:
  25. + case USB_SPEED_SUPER:
  26. + case USB_SPEED_SUPER_PLUS:
  27. + break;
  28. + default:
  29. + dev_err(dev, "invalid maximum_speed parameter %d\n",
  30. + dwc->maximum_speed);
  31. + /* fall through */
  32. + case USB_SPEED_UNKNOWN:
  33. + /* default to superspeed */
  34. dwc->maximum_speed = USB_SPEED_SUPER;
  35. /*
  36. @@ -1023,6 +1035,8 @@ static int dwc3_probe(struct platform_de
  37. (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
  38. DWC3_GHWPARAMS3_SSPHY_IFC_GEN2))
  39. dwc->maximum_speed = USB_SPEED_SUPER_PLUS;
  40. +
  41. + break;
  42. }
  43. /* Adjust Frame Length */
  44. --- a/drivers/usb/dwc3/gadget.c
  45. +++ b/drivers/usb/dwc3/gadget.c
  46. @@ -1647,10 +1647,13 @@ static int dwc3_gadget_start(struct usb_
  47. case USB_SPEED_HIGH:
  48. reg |= DWC3_DSTS_HIGHSPEED;
  49. break;
  50. - case USB_SPEED_SUPER: /* FALLTHROUGH */
  51. - case USB_SPEED_UNKNOWN: /* FALTHROUGH */
  52. default:
  53. - reg |= DWC3_DSTS_SUPERSPEED;
  54. + dev_err(dwc->dev, "invalid dwc->maximum_speed (%d)\n",
  55. + dwc->maximum_speed);
  56. + /* fall through */
  57. + case USB_SPEED_SUPER:
  58. + reg |= DWC3_DCFG_SUPERSPEED;
  59. + break;
  60. }
  61. }
  62. dwc3_writel(dwc->regs, DWC3_DCFG, reg);