public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* regulator_get_optional() no longer returning NULL?
@ 2017-02-01 22:23 Dmitry Torokhov
  2017-02-03 11:20 ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Torokhov @ 2017-02-01 22:23 UTC (permalink / raw)
  To: Mark Brown; +Cc: Thierry Reding, Jelle van der Waa, Linus Walleij, linux-kernel

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;
        }
 

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

end of thread, other threads:[~2017-02-04 10:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-01 22:23 regulator_get_optional() no longer returning NULL? Dmitry Torokhov
2017-02-03 11:20 ` Mark Brown
2017-02-03 21:51   ` Dmitry Torokhov
2017-02-04 10:08     ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox