Commit 02337a14 authored by Tomeu Vizoso's avatar Tomeu Vizoso

usb: dwc2: dwc2_vbus_supply_init: fix error check

devm_regulator_get_optional returns -ENODEV if the regulator isn't
there, so if that's the case we have to make sure not to leave -ENODEV
in the regulator pointer.

Also, make sure we return 0 in that case, but correctly propagate any
other errors. Also propagate the error from _dwc2_hcd_start.

Fixes: 531ef5eb ("usb: dwc2: add support for host mode external vbus supply")
Cc: Amelie Delaunay <>
Signed-off-by: Tomeu Vizoso's avatarTomeu Vizoso <>
parent 2f27c46e
...@@ -359,8 +359,13 @@ static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg) ...@@ -359,8 +359,13 @@ static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg)
static int dwc2_vbus_supply_init(struct dwc2_hsotg *hsotg) static int dwc2_vbus_supply_init(struct dwc2_hsotg *hsotg)
{ {
hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus"); hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus");
if (IS_ERR(hsotg->vbus_supply)) if (IS_ERR(hsotg->vbus_supply)) {
return 0; hsotg->vbus_supply = NULL;
if (PTR_ERR(hsotg->vbus_supply) == -ENODEV)
return 0;
return PTR_ERR(hsotg->vbus_supply);
return regulator_enable(hsotg->vbus_supply); return regulator_enable(hsotg->vbus_supply);
} }
...@@ -4342,9 +4347,7 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd) ...@@ -4342,9 +4347,7 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd)
spin_unlock_irqrestore(&hsotg->lock, flags); spin_unlock_irqrestore(&hsotg->lock, flags);
dwc2_vbus_supply_init(hsotg); return dwc2_vbus_supply_init(hsotg);
return 0;
} }
/* /*
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment