Skip to contentSkip to conversation

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

PATCH In review Maxime Ripard 3 participants 8 messages Jan 10, 2018 – Jan 15, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

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

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")
---
 drivers/gpu/drm/panel/panel-lvds.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/panel/panel-lvds.c +7 -2
index 57e38a9e7ab4..9f46e7095c0e 100644
@@ -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. */
Signature · 6 lines
2.14.3

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer
#1 lore raw

Hi Maxime,

(CC'ing Mark Brown)

Thank you for the patch.

Quoted 19 lines · 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 <[email protected]>

---
 drivers/gpu/drm/panel/panel-lvds.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/panel/panel-lvds.c index 57e38a9e7ab4..9f46e7095c0e 100644

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_probe(struct platform_device · line 221

Quoted 9 lines
drivers/gpu/drm/panel/panel-lvds.c +4 -2
@@ -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.

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_probe(struct platform_device *pdev) · line 225

Quoted 4 lines
drivers/gpu/drm/panel/panel-lvds.c +3 -0
+		} 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 ?

Quoted 1 line
drivers/gpu/drm/panel/panel-lvds.c +0 -0
 	/* Get GPIOs and backlight controller. */
Signature · 3 lines
Regards,

Laurent Pinchart
#2 lore raw

Hi,

Quoted 45 lines · Laurent Pinchart

Hi Maxime,

(CC'ing Mark Brown)

Thank you for the patch.

Quoted 19 lines · 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 <[email protected]>

---
 drivers/gpu/drm/panel/panel-lvds.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/panel/panel-lvds.c index 57e38a9e7ab4..9f46e7095c0e 100644

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_probe(struct platform_device · line 221

Quoted 9 lines
drivers/gpu/drm/panel/panel-lvds.c +4 -2
@@ -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.

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_probe(struct platform_device *pdev) · line 225

Quoted 4 lines
drivers/gpu/drm/panel/panel-lvds.c +3 -0
+		} else {
+			lvds->supply = NULL;
+		}
 	}

How about

Quoted 5 lines
	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

Quoted 6 lines
				dev_err(lvds->dev, "failed to request regulator: %d\n", ret);
			return ret;
		}

		lvds->supply = NULL;
	}

Otherwise, it works for me.

Quoted 4 lines

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

Signature · 3 lines
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
maintainer
#3 lore raw

Hi Maxime,

Quoted 43 lines · On Thursday, 11 January 2018 15:12:56 EET Maxime Ripard wrote:
Quoted 42 lines · Laurent Pinchart
Quoted 21 lines · 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
<[email protected]>
---

 drivers/gpu/drm/panel/panel-lvds.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/panel/panel-lvds.c index 57e38a9e7ab4..9f46e7095c0e 100644

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_probe(struct platform_device · line 222

Quoted 10 lines
drivers/gpu/drm/panel/panel-lvds.c +4 -2
@@ -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.

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_probe(struct platform_device *pdev) · line 225

Quoted 4 lines
drivers/gpu/drm/panel/panel-lvds.c +3 -0
+		} else {
+			lvds->supply = NULL;
+		}
 	}

How about

Quoted 7 lines
Quoted 5 lines
	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.

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

Otherwise, it works for me.

Quoted 8 lines
Quoted 5 lines

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 ;-)).

Signature · 8 lines
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer Reviewed-by Tested-by
#4 lore raw

Hi Maxime,

Quoted 50 lines · On Friday, 12 January 2018 00:06:06 EET Laurent Pinchart wrote:
Quoted 49 lines · On Thursday, 11 January 2018 15:12:56 EET Maxime Ripard wrote:
Quoted 47 lines · Laurent Pinchart
Quoted 21 lines · 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
<[email protected]>
---

 drivers/gpu/drm/panel/panel-lvds.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/panel/panel-lvds.c index 57e38a9e7ab4..9f46e7095c0e 100644

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_probe(struct platform_device · line 222

Quoted 10 lines
drivers/gpu/drm/panel/panel-lvds.c +4 -2
@@ -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.

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_probe(struct platform_device *pdev) · line 225

Quoted 4 lines
drivers/gpu/drm/panel/panel-lvds.c +3 -0
+		} 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)
Quoted 12 lines
Quoted 1 line

I guess that would be != -EPROBE_DEFER

Of course, my bad.

Quoted 8 lines
Quoted 6 lines
				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,

Quoted 12 lines
Quoted 8 lines
Quoted 5 lines

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 ;-)).

Signature · 8 lines
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author Applied
#5 lore raw
Quoted 64 lines · Laurent Pinchart

Hi Maxime,

Quoted 61 lines · On Friday, 12 January 2018 00:06:06 EET Laurent Pinchart wrote:
Quoted 43 lines · On Thursday, 11 January 2018 15:12:56 EET Maxime Ripard wrote:
Quoted 42 lines · Laurent Pinchart
Quoted 21 lines · 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
<[email protected]>
---

 drivers/gpu/drm/panel/panel-lvds.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/panel/panel-lvds.c index 57e38a9e7ab4..9f46e7095c0e 100644

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_probe(struct platform_device · line 222

Quoted 10 lines
drivers/gpu/drm/panel/panel-lvds.c +4 -2
@@ -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.

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_probe(struct platform_device *pdev) · line 225

Quoted 4 lines
drivers/gpu/drm/panel/panel-lvds.c +3 -0
+		} else {
+			lvds->supply = NULL;
+		}
 	}

How about

Quoted 7 lines
Quoted 5 lines
	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.

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

Otherwise, it works for me.

With the above change,

Applied to drm-misc-next-fixes.

Maxime

Signature · 3 lines
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#6 lore raw
In reply to Laurent Pinchart
Quoted 4 lines · Laurent Pinchart

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.

Signature · 1 line
Jani Nikula, Intel Open Source Technology Center
maintainer
#7 lore raw

Hi Jani,

Quoted 9 lines · On Thursday, 11 January 2018 16:31:59 EET Jani Nikula wrote:
Quoted 5 lines · Laurent Pinchart

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.

Signature · 8 lines
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel