59ab805cf6723f3da33772bd28b12ed720b57f32
[openwrt/staging/luka.git] /
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
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.
9
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.
12
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>
22 ---
23 drivers/usb/dwc2/hcd.c | 13 ++++++++-----
24 1 file changed, 8 insertions(+), 5 deletions(-)
25
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
29
30 static int dwc2_vbus_supply_init(struct dwc2_hsotg *hsotg)
31 {
32 + int ret;
33 +
34 hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus");
35 - if (IS_ERR(hsotg->vbus_supply))
36 - return 0;
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;
41 + }
42
43 return regulator_enable(hsotg->vbus_supply);
44 }
45 @@ -4467,9 +4472,7 @@ static int _dwc2_hcd_start(struct usb_hc
46
47 spin_unlock_irqrestore(&hsotg->lock, flags);
48
49 - dwc2_vbus_supply_init(hsotg);
50 -
51 - return 0;
52 + return dwc2_vbus_supply_init(hsotg);
53 }
54
55 /*