From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Mark Brown <broonie@kernel.org>
Cc: Thierry Reding <treding@nvidia.com>,
Jelle van der Waa <jelle@vdwaa.nl>,
Linus Walleij <linus.walleij@linaro.org>,
linux-kernel@vger.kernel.org
Subject: regulator_get_optional() no longer returning NULL?
Date: Wed, 1 Feb 2017 14:23:31 -0800 [thread overview]
Message-ID: <20170201222331.GE40720@dtor-ws> (raw)
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)
do_stuff();
vs.
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
rot).
Can we please revert this patch?
Thanks!
--
Dmitry
commit ef60abbb6b406389245225ab4acfe73f66e7d92c
Author: Mark Brown <broonie@linaro.org>
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 <treding@nvidia.com>
Tested-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
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;
}
next reply other threads:[~2017-02-01 22:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-01 22:23 Dmitry Torokhov [this message]
2017-02-03 11:20 ` regulator_get_optional() no longer returning NULL? Mark Brown
2017-02-03 21:51 ` Dmitry Torokhov
2017-02-04 10:08 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170201222331.GE40720@dtor-ws \
--to=dmitry.torokhov@gmail.com \
--cc=broonie@kernel.org \
--cc=jelle@vdwaa.nl \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=treding@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox