030-v4.17-0002-usb-dwc2-dwc2_vbus_supply_init-fix-error-check.patch 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. From 438fea2a6325933868aebc20279e2669c9a21207 Mon Sep 17 00:00:00 2001
  2. From: Tomeu Vizoso <tomeu.vizoso@collabora.com>
  3. Date: Mon, 26 Mar 2018 11:00:01 +0200
  4. Subject: [PATCH] usb: dwc2: dwc2_vbus_supply_init: fix error check
  5. devm_regulator_get_optional returns -ENODEV if the regulator isn't
  6. there, so if that's the case we have to make sure not to leave -ENODEV
  7. in the regulator pointer.
  8. Also, make sure we return 0 in that case, but correctly propagate any
  9. other errors. Also propagate the error from _dwc2_hcd_start.
  10. Fixes: 531ef5ebea96 ("usb: dwc2: add support for host mode external vbus supply")
  11. Cc: Amelie Delaunay <amelie.delaunay@st.com>
  12. Reviewed-by: Amelie Delaunay <amelie.delaunay@st.com>
  13. Reviewed-by: Heiko Stuebner <heiko@sntech.de>
  14. Reviewed-by: Grigor Tovmasyan <tovmasya@synopsys.com>
  15. Tested-by: Heiko Stuebner <heiko@sntech.de>
  16. Acked-by: Minas Harutyunyan <hminas@synopsys.com>
  17. Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
  18. Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
  19. ---
  20. drivers/usb/dwc2/hcd.c | 13 ++++++++-----
  21. 1 file changed, 8 insertions(+), 5 deletions(-)
  22. --- a/drivers/usb/dwc2/hcd.c
  23. +++ b/drivers/usb/dwc2/hcd.c
  24. @@ -361,9 +361,14 @@ static void dwc2_gusbcfg_init(struct dwc
  25. static int dwc2_vbus_supply_init(struct dwc2_hsotg *hsotg)
  26. {
  27. + int ret;
  28. +
  29. hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus");
  30. - if (IS_ERR(hsotg->vbus_supply))
  31. - return 0;
  32. + if (IS_ERR(hsotg->vbus_supply)) {
  33. + ret = PTR_ERR(hsotg->vbus_supply);
  34. + hsotg->vbus_supply = NULL;
  35. + return ret == -ENODEV ? 0 : ret;
  36. + }
  37. return regulator_enable(hsotg->vbus_supply);
  38. }
  39. @@ -4475,9 +4480,7 @@ static int _dwc2_hcd_start(struct usb_hc
  40. spin_unlock_irqrestore(&hsotg->lock, flags);
  41. - dwc2_vbus_supply_init(hsotg);
  42. -
  43. - return 0;
  44. + return dwc2_vbus_supply_init(hsotg);
  45. }
  46. /*