linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* usb: dwc2: dwc2_vbus_supply_init: fix error check
@ 2018-03-22  9:39 Tomeu Vizoso
  0 siblings, 0 replies; 4+ messages in thread
From: Tomeu Vizoso @ 2018-03-22  9:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: Felipe Balbi, Heiko Stuebner, Tomeu Vizoso, Amelie Delaunay,
	Minas Harutyunyan, Greg Kroah-Hartman, linux-usb

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: 531ef5ebea96 ("usb: dwc2: add support for host mode external vbus supply")
Cc: Amelie Delaunay <amelie.delaunay@st.com>
Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---
 drivers/usb/dwc2/hcd.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index dcfda5eb4cac..4ae211f65e85 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -359,8 +359,13 @@ static void dwc2_gusbcfg_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");
-	if (IS_ERR(hsotg->vbus_supply))
-		return 0;
+	if (IS_ERR(hsotg->vbus_supply)) {
+		hsotg->vbus_supply = NULL;
+		if (PTR_ERR(hsotg->vbus_supply) == -ENODEV)
+			return 0;
+		else
+			return PTR_ERR(hsotg->vbus_supply);
+	}
 
 	return regulator_enable(hsotg->vbus_supply);
 }
@@ -4342,9 +4347,7 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd)
 
 	spin_unlock_irqrestore(&hsotg->lock, flags);
 
-	dwc2_vbus_supply_init(hsotg);
-
-	return 0;
+	return dwc2_vbus_supply_init(hsotg);
 }
 
 /*

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* usb: dwc2: dwc2_vbus_supply_init: fix error check
@ 2018-03-22 11:39 Heiko Stuebner
  0 siblings, 0 replies; 4+ messages in thread
From: Heiko Stuebner @ 2018-03-22 11:39 UTC (permalink / raw)
  To: Tomeu Vizoso
  Cc: linux-kernel, Felipe Balbi, Amelie Delaunay, Minas Harutyunyan,
	Greg Kroah-Hartman, linux-usb

Am Donnerstag, 22. März 2018, 10:39:43 CET schrieb Tomeu Vizoso:
> 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: 531ef5ebea96 ("usb: dwc2: add support for host mode external vbus
> supply") Cc: Amelie Delaunay <amelie.delaunay@st.com>
> Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>

Thanks for catching that oops in your tests.
Reviewed-by: Heiko Stuebner <heiko@sntech.de>


> ---
>  drivers/usb/dwc2/hcd.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
> index dcfda5eb4cac..4ae211f65e85 100644
> --- a/drivers/usb/dwc2/hcd.c
> +++ b/drivers/usb/dwc2/hcd.c
> @@ -359,8 +359,13 @@ static void dwc2_gusbcfg_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");
> -	if (IS_ERR(hsotg->vbus_supply))
> -		return 0;
> +	if (IS_ERR(hsotg->vbus_supply)) {
> +		hsotg->vbus_supply = NULL;
> +		if (PTR_ERR(hsotg->vbus_supply) == -ENODEV)
> +			return 0;
> +		else
> +			return PTR_ERR(hsotg->vbus_supply);
> +	}
> 
>  	return regulator_enable(hsotg->vbus_supply);
>  }
> @@ -4342,9 +4347,7 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd)
> 
>  	spin_unlock_irqrestore(&hsotg->lock, flags);
> 
> -	dwc2_vbus_supply_init(hsotg);
> -
> -	return 0;
> +	return dwc2_vbus_supply_init(hsotg);
>  }
> 
>  /*
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* usb: dwc2: dwc2_vbus_supply_init: fix error check
@ 2018-03-22 11:41 Heiko Stuebner
  0 siblings, 0 replies; 4+ messages in thread
From: Heiko Stuebner @ 2018-03-22 11:41 UTC (permalink / raw)
  To: Tomeu Vizoso
  Cc: linux-kernel, Felipe Balbi, Amelie Delaunay, Minas Harutyunyan,
	Greg Kroah-Hartman, linux-usb

Hi Tomeu,

Am Donnerstag, 22. März 2018, 12:39:13 CET schrieb Heiko Stübner:
> Am Donnerstag, 22. März 2018, 10:39:43 CET schrieb Tomeu Vizoso:
> > 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: 531ef5ebea96 ("usb: dwc2: add support for host mode external vbus
> > supply") Cc: Amelie Delaunay <amelie.delaunay@st.com>
> > Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> 
> Thanks for catching that oops in your tests.
> Reviewed-by: Heiko Stuebner <heiko@sntech.de>

I take that back :-)
see below

> > ---
> > 
> >  drivers/usb/dwc2/hcd.c | 13 ++++++++-----
> >  1 file changed, 8 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
> > index dcfda5eb4cac..4ae211f65e85 100644
> > --- a/drivers/usb/dwc2/hcd.c
> > +++ b/drivers/usb/dwc2/hcd.c
> > @@ -359,8 +359,13 @@ static void dwc2_gusbcfg_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");
> > 
> > -	if (IS_ERR(hsotg->vbus_supply))
> > -		return 0;
> > +	if (IS_ERR(hsotg->vbus_supply)) {
> > +		hsotg->vbus_supply = NULL;
> > +		if (PTR_ERR(hsotg->vbus_supply) == -ENODEV)

hsotg->vbus_supply is already NULL here
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* usb: dwc2: dwc2_vbus_supply_init: fix error check
@ 2018-03-22 12:21 Amelie Delaunay
  0 siblings, 0 replies; 4+ messages in thread
From: Amelie Delaunay @ 2018-03-22 12:21 UTC (permalink / raw)
  To: Heiko Stübner, Tomeu Vizoso
  Cc: linux-kernel@vger.kernel.org, Felipe Balbi, Minas Harutyunyan,
	Greg Kroah-Hartman, linux-usb@vger.kernel.org

SGkgSGVpa28sDQpIaSBUb21ldSwNCg0KT24gMDMvMjIvMjAxOCAxMjo0MSBQTSwgSGVpa28gU3TD
vGJuZXIgd3JvdGU6DQo+IEhpIFRvbWV1LA0KPiANCj4gQW0gRG9ubmVyc3RhZywgMjIuIE3DpHJ6
IDIwMTgsIDEyOjM5OjEzIENFVCBzY2hyaWViIEhlaWtvIFN0w7xibmVyOg0KPj4gQW0gRG9ubmVy
c3RhZywgMjIuIE3DpHJ6IDIwMTgsIDEwOjM5OjQzIENFVCBzY2hyaWViIFRvbWV1IFZpem9zbzoN
Cj4+PiBkZXZtX3JlZ3VsYXRvcl9nZXRfb3B0aW9uYWwgcmV0dXJucyAtRU5PREVWIGlmIHR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C4uLg0KICAqIFJldHVybnMgYSBzdHJ1Y3QgcmVndWxhdG9yIGNvcnJlc3Bv
bmRpbmcgdG8gdGhlIHJlZ3VsYXRvciBwcm9kdWNlciwNCiAgKiBvciBJU19FUlIoKSBjb25kaXRp
b24gY29udGFpbmluZyBlcnJuby4NCiAgKiAuLi4NCiAgKi8NCg0KWW91IGNhbiBhZGQgbXkgUmV2
aWV3ZWQtYnk6IEFtZWxpZSBEZWxhdW5heSA8YW1lbGllLmRlbGF1bmF5QHN0LmNvbT4NCg0KVGhh
bmtzIGZvciB0aGUgZml4LA0KQW1lbGll
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-03-22 12:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-22 11:39 usb: dwc2: dwc2_vbus_supply_init: fix error check Heiko Stuebner
  -- strict thread matches above, loose matches on Subject: below --
2018-03-22 12:21 Amelie Delaunay
2018-03-22 11:41 Heiko Stuebner
2018-03-22  9:39 Tomeu Vizoso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).