[lkml]   [2017]   [Feb]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subjectregulator_get_optional() no longer returning NULL?
Hi Mark,

It appears that [devm_]regulator_get_optional() and
[devm_]gpiod_get_optional() behave irritatingly differently. While the
latter returns NULL for non-existing GPIOs, the former started returning
-ENODEV instead of NULL, starting with commit below.

Why did we do that? It is much more convenient to write:

data->vcc = devm_regulator_get_optional(dev. "vcc");
if (IS_ERR(data->vcc))
return ERR_PTR(data->vcc);
if (data->vcc)


data->vcc = devm_regulator_get_optional(dev. "vcc");
if (IS_ERR(data->vcc)) {
error = ERR_PTR(data->vcc);
if (error != -ENODEV && error != <list of vetted codes>)
return error;

data->vcc = NULL;

I.e. it is nice to treat *all* codes returned by
devm_regulator_get_optional() as fatal and NULL as special instead of
vetting by hand (and having chance that list of vetted codes will bit

Can we please revert this patch?



commit ef60abbb6b406389245225ab4acfe73f66e7d92c
Author: Mark Brown <>
Date: Mon Sep 23 16:12:52 2013 +0100

regulator: core: Always use return value when regulator_dev_lookup() fails

Ensure that the return value is always set when we return now that the
logic has changed for regulator_get_optional() so we don't get missing
codes leaking out.

Reported-by: Thierry Reding <>
Tested-by: Thierry Reding <>
Signed-off-by: Mark Brown <>

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 088b41ac9506..a40055edaae4 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1263,12 +1263,13 @@ static struct regulator *_regulator_get(struct
device *dev, const char *id,
if (rdev)
goto found;

+ regulator = ERR_PTR(ret);
* If we have return value from dev_lookup fail, we do not
* expect to
* succeed, so, quit with appropriate error value
if (ret && ret != -ENODEV) {
- regulator = ERR_PTR(ret);
goto out;

 \ /
  Last update: 2017-02-01 23:24    [W:0.044 / U:3.836 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site