Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1572017

regulator_get_optional() no longer returning NULL?

From Dmitry Torokhov <dmitry.torokhov@gmail.com>
Newsgroups linux.kernel
Subject regulator_get_optional() no longer returning NULL?
Date 2017-02-01 23:30 +0100
Message-ID <t6bzz-3Hx-3@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View 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;
        }
 

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

regulator_get_optional() no longer returning NULL? Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-02-01 23:30 +0100
  Re: regulator_get_optional() no longer returning NULL? Mark Brown <broonie@kernel.org> - 2017-02-03 12:30 +0100
    Re: regulator_get_optional() no longer returning NULL? Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-02-03 23:00 +0100
      Re: regulator_get_optional() no longer returning NULL? Mark Brown <broonie@kernel.org> - 2017-02-04 11:10 +0100

csiph-web