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 <[email protected]>
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 <[email protected]>
    Tested-by: Thierry Reding <[email protected]>
    Signed-off-by: Mark Brown <[email protected]>

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

Reply via email to