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
6 devm_regulator_get_optional returns -ENODEV if the regulator isn't
7 there, so if that's the case we have to make sure not to leave -ENODEV
8 in the regulator pointer.
10 Also, make sure we return 0 in that case, but correctly propagate any
11 other errors. Also propagate the error from _dwc2_hcd_start.
13 Fixes: 531ef5ebea96 ("usb: dwc2: add support for host mode external vbus supply")
14 Cc: Amelie Delaunay <amelie.delaunay@st.com>
15 Reviewed-by: Amelie Delaunay <amelie.delaunay@st.com>
16 Reviewed-by: Heiko Stuebner <heiko@sntech.de>
17 Reviewed-by: Grigor Tovmasyan <tovmasya@synopsys.com>
18 Tested-by: Heiko Stuebner <heiko@sntech.de>
19 Acked-by: Minas Harutyunyan <hminas@synopsys.com>
20 Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
21 Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
23 drivers/usb/dwc2/hcd.c | 13 ++++++++-----
24 1 file changed, 8 insertions(+), 5 deletions(-)
26 --- a/drivers/usb/dwc2/hcd.c
27 +++ b/drivers/usb/dwc2/hcd.c
28 @@ -361,9 +361,14 @@ static void dwc2_gusbcfg_init(struct dwc
30 static int dwc2_vbus_supply_init(struct dwc2_hsotg *hsotg)
34 hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus");
35 - if (IS_ERR(hsotg->vbus_supply))
37 + if (IS_ERR(hsotg->vbus_supply)) {
38 + ret = PTR_ERR(hsotg->vbus_supply);
39 + hsotg->vbus_supply = NULL;
40 + return ret == -ENODEV ? 0 : ret;
43 return regulator_enable(hsotg->vbus_supply);
45 @@ -4371,9 +4376,7 @@ static int _dwc2_hcd_start(struct usb_hc
47 spin_unlock_irqrestore(&hsotg->lock, flags);
49 - dwc2_vbus_supply_init(hsotg);
52 + return dwc2_vbus_supply_init(hsotg);