regulator: Don't return or expect -errno from of_map_mode()
authorDouglas Anderson <dianders@chromium.org>
Wed, 18 Apr 2018 15:54:18 +0000 (08:54 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 3 Aug 2018 05:50:40 +0000 (07:50 +0200)
[ Upstream commit 02f3703934a42417021405ef336fe45add13c3d1 ]

In of_get_regulation_constraints() we were taking the result of
of_map_mode() (an unsigned int) and assigning it to an int.  We were
then checking whether this value was -EINVAL.  Some implementers of
of_map_mode() were returning -EINVAL (even though the return type of
their function needed to be unsigned int) because they needed to
signal an error back to of_get_regulation_constraints().

In general in the regulator framework the mode is always referred to
as an unsigned int.  While we could fix this to be a signed int (the
highest value we store in there right now is 0x8), it's actually
pretty clean to just define the regulator mode 0x0 (the lack of any
bits set) as an invalid mode.  Let's do that.

Fixes: 5e5e3a42c653 ("regulator: of: Add support for parsing initial and suspend modes")
Suggested-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/regulator/cpcap-regulator.c
drivers/regulator/of_regulator.c
drivers/regulator/twl-regulator.c
include/linux/regulator/consumer.h

index f541b80f1b540ae12d47ece8de124b74839b1acf..bd910fe123d98e65794990a14d7c26986369b6cb 100644 (file)
@@ -222,7 +222,7 @@ static unsigned int cpcap_map_mode(unsigned int mode)
        case CPCAP_BIT_AUDIO_LOW_PWR:
                return REGULATOR_MODE_STANDBY;
        default:
-               return -EINVAL;
+               return REGULATOR_MODE_INVALID;
        }
 }
 
index c9875355905d159827ea565affd0b26b7bc18b01..a3bf7c993723acdaab9160b22be58a7e5d52b37a 100644 (file)
@@ -31,6 +31,7 @@ static void of_get_regulation_constraints(struct device_node *np,
        struct regulation_constraints *constraints = &(*init_data)->constraints;
        struct regulator_state *suspend_state;
        struct device_node *suspend_np;
+       unsigned int mode;
        int ret, i;
        u32 pval;
 
@@ -124,11 +125,11 @@ static void of_get_regulation_constraints(struct device_node *np,
 
        if (!of_property_read_u32(np, "regulator-initial-mode", &pval)) {
                if (desc && desc->of_map_mode) {
-                       ret = desc->of_map_mode(pval);
-                       if (ret == -EINVAL)
+                       mode = desc->of_map_mode(pval);
+                       if (mode == REGULATOR_MODE_INVALID)
                                pr_err("%s: invalid mode %u\n", np->name, pval);
                        else
-                               constraints->initial_mode = ret;
+                               constraints->initial_mode = mode;
                } else {
                        pr_warn("%s: mapping for mode %d not defined\n",
                                np->name, pval);
@@ -163,12 +164,12 @@ static void of_get_regulation_constraints(struct device_node *np,
                if (!of_property_read_u32(suspend_np, "regulator-mode",
                                          &pval)) {
                        if (desc && desc->of_map_mode) {
-                               ret = desc->of_map_mode(pval);
-                               if (ret == -EINVAL)
+                               mode = desc->of_map_mode(pval);
+                               if (mode == REGULATOR_MODE_INVALID)
                                        pr_err("%s: invalid mode %u\n",
                                               np->name, pval);
                                else
-                                       suspend_state->mode = ret;
+                                       suspend_state->mode = mode;
                        } else {
                                pr_warn("%s: mapping for mode %d not defined\n",
                                        np->name, pval);
index a4456db5849d06282b7eb2884d20e8da29093753..884c7505ed91c493b127e680b7406773952fc1d7 100644 (file)
@@ -274,7 +274,7 @@ static inline unsigned int twl4030reg_map_mode(unsigned int mode)
        case RES_STATE_SLEEP:
                return REGULATOR_MODE_STANDBY;
        default:
-               return -EINVAL;
+               return REGULATOR_MODE_INVALID;
        }
 }
 
index df176d7c2b87c00356a11b383a61185e7f3e47ae..25602afd48447f3c410f79082e966b1d4589d911 100644 (file)
@@ -80,6 +80,7 @@ struct regmap;
  * These modes can be OR'ed together to make up a mask of valid register modes.
  */
 
+#define REGULATOR_MODE_INVALID                 0x0
 #define REGULATOR_MODE_FAST                    0x1
 #define REGULATOR_MODE_NORMAL                  0x2
 #define REGULATOR_MODE_IDLE                    0x4