diff mbox

drm/panel: lvds: Handle the optional regulator case properly

Message ID 20180110155941.16109-1-maxime.ripard@free-electrons.com (mailing list archive)
State New, archived
Headers show

Commit Message

Maxime Ripard Jan. 10, 2018, 3:59 p.m. UTC
The devm_regulator_get_optional function, unlike it was assumed in the
commit a1c55bccf600 ("drm/panel: lvds: Add support for the power-supply
property"), is actually returning an error pointer with -ENODEV instead of
NULL when there's no regulator to find.

Make sure we handle that case properly.

Fixes: a1c55bccf600 ("drm/panel: lvds: Add support for the power-supply property")
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 drivers/gpu/drm/panel/panel-lvds.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Laurent Pinchart Jan. 11, 2018, 1:05 p.m. UTC | #1
Hi Maxime,

(CC'ing Mark Brown)

Thank you for the patch.

On Wednesday, 10 January 2018 17:59:41 EET Maxime Ripard wrote:
> The devm_regulator_get_optional function, unlike it was assumed in the
> commit a1c55bccf600 ("drm/panel: lvds: Add support for the power-supply
> property"), is actually returning an error pointer with -ENODEV instead of
> NULL when there's no regulator to find.
> 
> Make sure we handle that case properly.
> 
> Fixes: a1c55bccf600 ("drm/panel: lvds: Add support for the power-supply
> property") Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> ---
>  drivers/gpu/drm/panel/panel-lvds.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panel/panel-lvds.c
> b/drivers/gpu/drm/panel/panel-lvds.c index 57e38a9e7ab4..9f46e7095c0e
> 100644
> --- a/drivers/gpu/drm/panel/panel-lvds.c
> +++ b/drivers/gpu/drm/panel/panel-lvds.c
> @@ -215,8 +215,13 @@ static int panel_lvds_probe(struct platform_device
> *pdev) lvds->supply = devm_regulator_get_optional(lvds->dev, "power");
>  	if (IS_ERR(lvds->supply)) {
>  		ret = PTR_ERR(lvds->supply);
> -		dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
> -		return ret;
> +
> +		if (ret != -ENODEV) {
> +			dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
> +			return ret;

I wouldn't print an error message if ret == -EPROBE_DEFER.

> +		} else {
> +			lvds->supply = NULL;
> +		}
>  	}

How about

	lvds->supply = devm_regulator_get_optional(lvds->dev, "power");
	if (IS_ERR(lvds->supply)) {
		ret = PTR_ERR(lvds->supply);
		if (ret != -ENODEV) {
			if (ret == -EPROBE_DEFER)
				dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
			return ret;
		}

		lvds->supply = NULL;
	}

My preference, however, would be for devm_regulator_get_optional() to return 
NULL when no regulator is present. The current implementation returns -ENODEV 
in multiple cases, making it impossible to properly discriminate between 
having no regulator and not being able to get the regulator due to an error.

Mark, what do you think about this ?

>  	/* Get GPIOs and backlight controller. */
Maxime Ripard Jan. 11, 2018, 1:12 p.m. UTC | #2
Hi,

On Thu, Jan 11, 2018 at 03:05:01PM +0200, Laurent Pinchart wrote:
> Hi Maxime,
> 
> (CC'ing Mark Brown)
> 
> Thank you for the patch.
> 
> On Wednesday, 10 January 2018 17:59:41 EET Maxime Ripard wrote:
> > The devm_regulator_get_optional function, unlike it was assumed in the
> > commit a1c55bccf600 ("drm/panel: lvds: Add support for the power-supply
> > property"), is actually returning an error pointer with -ENODEV instead of
> > NULL when there's no regulator to find.
> > 
> > Make sure we handle that case properly.
> > 
> > Fixes: a1c55bccf600 ("drm/panel: lvds: Add support for the power-supply
> > property") Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> > ---
> >  drivers/gpu/drm/panel/panel-lvds.c | 9 +++++++--
> >  1 file changed, 7 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/panel/panel-lvds.c
> > b/drivers/gpu/drm/panel/panel-lvds.c index 57e38a9e7ab4..9f46e7095c0e
> > 100644
> > --- a/drivers/gpu/drm/panel/panel-lvds.c
> > +++ b/drivers/gpu/drm/panel/panel-lvds.c
> > @@ -215,8 +215,13 @@ static int panel_lvds_probe(struct platform_device
> > *pdev) lvds->supply = devm_regulator_get_optional(lvds->dev, "power");
> >  	if (IS_ERR(lvds->supply)) {
> >  		ret = PTR_ERR(lvds->supply);
> > -		dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
> > -		return ret;
> > +
> > +		if (ret != -ENODEV) {
> > +			dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
> > +			return ret;
> 
> I wouldn't print an error message if ret == -EPROBE_DEFER.
> 
> > +		} else {
> > +			lvds->supply = NULL;
> > +		}
> >  	}
> 
> How about
> 
> 	lvds->supply = devm_regulator_get_optional(lvds->dev, "power");
> 	if (IS_ERR(lvds->supply)) {
> 		ret = PTR_ERR(lvds->supply);
> 		if (ret != -ENODEV) {
> 			if (ret == -EPROBE_DEFER)

I guess that would be != -EPROBE_DEFER

> 				dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
> 			return ret;
> 		}
> 
> 		lvds->supply = NULL;
> 	}

Otherwise, it works for me.

> My preference, however, would be for devm_regulator_get_optional() to return 
> NULL when no regulator is present. The current implementation returns -ENODEV 
> in multiple cases, making it impossible to properly discriminate between 
> having no regulator and not being able to get the regulator due to an error.

It would feel more intuitive to me too, but it would also require to
fix most of the call sites that would have a similar pattern.

Maxime
Jani Nikula Jan. 11, 2018, 2:31 p.m. UTC | #3
On Thu, 11 Jan 2018, Laurent Pinchart <laurent.pinchart@ideasonboard.com> wrote:
> My preference, however, would be for devm_regulator_get_optional() to return 
> NULL when no regulator is present. The current implementation returns -ENODEV 
> in multiple cases, making it impossible to properly discriminate between 
> having no regulator and not being able to get the regulator due to an error.

Just a word of warning, IS_ERR(NULL) is false, and your proposed change
would apparently require quite a churn all over the kernel.

BR,
Jani.
Laurent Pinchart Jan. 11, 2018, 9:30 p.m. UTC | #4
Hi Jani,

On Thursday, 11 January 2018 16:31:59 EET Jani Nikula wrote:
> On Thu, 11 Jan 2018, Laurent Pinchart wrote:
> > My preference, however, would be for devm_regulator_get_optional() to
> > return NULL when no regulator is present. The current implementation
> > returns -ENODEV in multiple cases, making it impossible to properly
> > discriminate between having no regulator and not being able to get the
> > regulator due to an error.
> 
> Just a word of warning, IS_ERR(NULL) is false, and your proposed change
> would apparently require quite a churn all over the kernel.

That's correct, but I still think that would make the API clearer. I don't 
want to block this patch until we make such a change, but it's a good 
opportunity to discuss it. I'd like to know what Mark's opinion is.
Laurent Pinchart Jan. 11, 2018, 10:06 p.m. UTC | #5
Hi Maxime,

On Thursday, 11 January 2018 15:12:56 EET Maxime Ripard wrote:
> On Thu, Jan 11, 2018 at 03:05:01PM +0200, Laurent Pinchart wrote:
> > On Wednesday, 10 January 2018 17:59:41 EET Maxime Ripard wrote:
> >> The devm_regulator_get_optional function, unlike it was assumed in the
> >> commit a1c55bccf600 ("drm/panel: lvds: Add support for the power-supply
> >> property"), is actually returning an error pointer with -ENODEV instead
> >> of NULL when there's no regulator to find.
> >> 
> >> Make sure we handle that case properly.
> >> 
> >> Fixes: a1c55bccf600 ("drm/panel: lvds: Add support for the power-supply
> >> property") Signed-off-by: Maxime Ripard
> >> <maxime.ripard@free-electrons.com>
> >> ---
> >> 
> >>  drivers/gpu/drm/panel/panel-lvds.c | 9 +++++++--
> >>  1 file changed, 7 insertions(+), 2 deletions(-)
> >> 
> >> diff --git a/drivers/gpu/drm/panel/panel-lvds.c
> >> b/drivers/gpu/drm/panel/panel-lvds.c index 57e38a9e7ab4..9f46e7095c0e
> >> 100644
> >> --- a/drivers/gpu/drm/panel/panel-lvds.c
> >> +++ b/drivers/gpu/drm/panel/panel-lvds.c
> >> @@ -215,8 +215,13 @@ static int panel_lvds_probe(struct platform_device
> >> *pdev)
> >> 	lvds->supply = devm_regulator_get_optional(lvds->dev, "power");
> >>  	if (IS_ERR(lvds->supply)) {
> >>  		ret = PTR_ERR(lvds->supply);
> >> -		dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
> >> -		return ret;
> >> +
> >> +		if (ret != -ENODEV) {
> >> +			dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
> >> +			return ret;
> > 
> > I wouldn't print an error message if ret == -EPROBE_DEFER.
> > 
> >> +		} else {
> >> +			lvds->supply = NULL;
> >> +		}
> >>  	}
> > 
> > How about
> > 
> > 	lvds->supply = devm_regulator_get_optional(lvds->dev, "power");
> > 	if (IS_ERR(lvds->supply)) {
> > 		ret = PTR_ERR(lvds->supply);
> > 		if (ret != -ENODEV) {
> > 			if (ret == -EPROBE_DEFER)
> 
> I guess that would be != -EPROBE_DEFER

Of course, my bad.

> > 				dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
> > 			return ret;
> > 		}
> > 		
> > 		lvds->supply = NULL;
> > 	}
> 
> Otherwise, it works for me.
> 
> > My preference, however, would be for devm_regulator_get_optional() to
> > return NULL when no regulator is present. The current implementation
> > returns -ENODEV in multiple cases, making it impossible to properly
> > discriminate between having no regulator and not being able to get the
> > regulator due to an error.
> 
> It would feel more intuitive to me too, but it would also require to
> fix most of the call sites that would have a similar pattern.

Of course. I don't mean we need to delay this patch, but I still think it 
would be a good API improvement that could be developed separately (and of 
course I wouldn't complain if you volunteered ;-)).
Laurent Pinchart Jan. 11, 2018, 10:09 p.m. UTC | #6
Hi Maxime,

On Friday, 12 January 2018 00:06:06 EET Laurent Pinchart wrote:
> On Thursday, 11 January 2018 15:12:56 EET Maxime Ripard wrote:
> > On Thu, Jan 11, 2018 at 03:05:01PM +0200, Laurent Pinchart wrote:
> >> On Wednesday, 10 January 2018 17:59:41 EET Maxime Ripard wrote:
> >>> The devm_regulator_get_optional function, unlike it was assumed in the
> >>> commit a1c55bccf600 ("drm/panel: lvds: Add support for the power-supply
> >>> property"), is actually returning an error pointer with -ENODEV instead
> >>> of NULL when there's no regulator to find.
> >>> 
> >>> Make sure we handle that case properly.
> >>> 
> >>> Fixes: a1c55bccf600 ("drm/panel: lvds: Add support for the power-supply
> >>> property") Signed-off-by: Maxime Ripard
> >>> <maxime.ripard@free-electrons.com>
> >>> ---
> >>> 
> >>>  drivers/gpu/drm/panel/panel-lvds.c | 9 +++++++--
> >>>  1 file changed, 7 insertions(+), 2 deletions(-)
> >>> 
> >>> diff --git a/drivers/gpu/drm/panel/panel-lvds.c
> >>> b/drivers/gpu/drm/panel/panel-lvds.c index 57e38a9e7ab4..9f46e7095c0e
> >>> 100644
> >>> --- a/drivers/gpu/drm/panel/panel-lvds.c
> >>> +++ b/drivers/gpu/drm/panel/panel-lvds.c
> >>> @@ -215,8 +215,13 @@ static int panel_lvds_probe(struct platform_device
> >>> *pdev)
> >>> 	lvds->supply = devm_regulator_get_optional(lvds->dev, "power");
> >>>  	if (IS_ERR(lvds->supply)) {
> >>>  		ret = PTR_ERR(lvds->supply);
> >>> -		dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
> >>> -		return ret;
> >>> +
> >>> +		if (ret != -ENODEV) {
> >>> +			dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
> >>> +			return ret;
> >> 
> >> I wouldn't print an error message if ret == -EPROBE_DEFER.
> >> 
> >>> +		} else {
> >>> +			lvds->supply = NULL;
> >>> +		}
> >>>  	}
> >> 
> >> How about
> >> 
> >> 	lvds->supply = devm_regulator_get_optional(lvds->dev, "power");
> >> 	if (IS_ERR(lvds->supply)) {
> >> 		ret = PTR_ERR(lvds->supply);
> >> 		if (ret != -ENODEV) {
> >> 			if (ret == -EPROBE_DEFER)
> > 
> > I guess that would be != -EPROBE_DEFER
> 
> Of course, my bad.
> 
> >> 				dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
> >> 			return ret;
> >> 		}
> >> 		
> >> 		lvds->supply = NULL;
> >> 	}
> > 
> > Otherwise, it works for me.

With the above change,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> >> My preference, however, would be for devm_regulator_get_optional() to
> >> return NULL when no regulator is present. The current implementation
> >> returns -ENODEV in multiple cases, making it impossible to properly
> >> discriminate between having no regulator and not being able to get the
> >> regulator due to an error.
> > 
> > It would feel more intuitive to me too, but it would also require to
> > fix most of the call sites that would have a similar pattern.
> 
> Of course. I don't mean we need to delay this patch, but I still think it
> would be a good API improvement that could be developed separately (and of
> course I wouldn't complain if you volunteered ;-)).
Maxime Ripard Jan. 15, 2018, 9:18 a.m. UTC | #7
On Fri, Jan 12, 2018 at 12:09:39AM +0200, Laurent Pinchart wrote:
> Hi Maxime,
> 
> On Friday, 12 January 2018 00:06:06 EET Laurent Pinchart wrote:
> > On Thursday, 11 January 2018 15:12:56 EET Maxime Ripard wrote:
> > > On Thu, Jan 11, 2018 at 03:05:01PM +0200, Laurent Pinchart wrote:
> > >> On Wednesday, 10 January 2018 17:59:41 EET Maxime Ripard wrote:
> > >>> The devm_regulator_get_optional function, unlike it was assumed in the
> > >>> commit a1c55bccf600 ("drm/panel: lvds: Add support for the power-supply
> > >>> property"), is actually returning an error pointer with -ENODEV instead
> > >>> of NULL when there's no regulator to find.
> > >>> 
> > >>> Make sure we handle that case properly.
> > >>> 
> > >>> Fixes: a1c55bccf600 ("drm/panel: lvds: Add support for the power-supply
> > >>> property") Signed-off-by: Maxime Ripard
> > >>> <maxime.ripard@free-electrons.com>
> > >>> ---
> > >>> 
> > >>>  drivers/gpu/drm/panel/panel-lvds.c | 9 +++++++--
> > >>>  1 file changed, 7 insertions(+), 2 deletions(-)
> > >>> 
> > >>> diff --git a/drivers/gpu/drm/panel/panel-lvds.c
> > >>> b/drivers/gpu/drm/panel/panel-lvds.c index 57e38a9e7ab4..9f46e7095c0e
> > >>> 100644
> > >>> --- a/drivers/gpu/drm/panel/panel-lvds.c
> > >>> +++ b/drivers/gpu/drm/panel/panel-lvds.c
> > >>> @@ -215,8 +215,13 @@ static int panel_lvds_probe(struct platform_device
> > >>> *pdev)
> > >>> 	lvds->supply = devm_regulator_get_optional(lvds->dev, "power");
> > >>>  	if (IS_ERR(lvds->supply)) {
> > >>>  		ret = PTR_ERR(lvds->supply);
> > >>> -		dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
> > >>> -		return ret;
> > >>> +
> > >>> +		if (ret != -ENODEV) {
> > >>> +			dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
> > >>> +			return ret;
> > >> 
> > >> I wouldn't print an error message if ret == -EPROBE_DEFER.
> > >> 
> > >>> +		} else {
> > >>> +			lvds->supply = NULL;
> > >>> +		}
> > >>>  	}
> > >> 
> > >> How about
> > >> 
> > >> 	lvds->supply = devm_regulator_get_optional(lvds->dev, "power");
> > >> 	if (IS_ERR(lvds->supply)) {
> > >> 		ret = PTR_ERR(lvds->supply);
> > >> 		if (ret != -ENODEV) {
> > >> 			if (ret == -EPROBE_DEFER)
> > > 
> > > I guess that would be != -EPROBE_DEFER
> > 
> > Of course, my bad.
> > 
> > >> 				dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
> > >> 			return ret;
> > >> 		}
> > >> 		
> > >> 		lvds->supply = NULL;
> > >> 	}
> > > 
> > > Otherwise, it works for me.
> 
> With the above change,
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Applied to drm-misc-next-fixes.

Maxime
diff mbox

Patch

diff --git a/drivers/gpu/drm/panel/panel-lvds.c b/drivers/gpu/drm/panel/panel-lvds.c
index 57e38a9e7ab4..9f46e7095c0e 100644
--- a/drivers/gpu/drm/panel/panel-lvds.c
+++ b/drivers/gpu/drm/panel/panel-lvds.c
@@ -215,8 +215,13 @@  static int panel_lvds_probe(struct platform_device *pdev)
 	lvds->supply = devm_regulator_get_optional(lvds->dev, "power");
 	if (IS_ERR(lvds->supply)) {
 		ret = PTR_ERR(lvds->supply);
-		dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
-		return ret;
+
+		if (ret != -ENODEV) {
+			dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
+			return ret;
+		} else {
+			lvds->supply = NULL;
+		}
 	}
 
 	/* Get GPIOs and backlight controller. */