gpio: Fix return value mismatch of function gpiod_get_from_of_node()
authorWaibel Georg <Georg.Waibel@sensor-technik.de>
Thu, 20 Jun 2019 21:37:08 +0000 (21:37 +0000)
committerMark Brown <broonie@kernel.org>
Tue, 25 Jun 2019 14:26:24 +0000 (15:26 +0100)
In case the requested gpio property is not found in the device tree, some
callers of gpiod_get_from_of_node() expect a return value of NULL, others
expect -ENOENT.
In particular devm_fwnode_get_index_gpiod_from_child() expects -ENOENT.
Currently it gets a NULL, which breaks the loop that tries all
gpio_suffixes. The result is that a gpio property is not found, even
though it is there.

This patch changes gpiod_get_from_of_node() to return -ENOENT instead
of NULL when the requested gpio property is not found in the device
tree. Additionally it modifies all calling functions to properly
evaluate the return value.

Another approach would be to leave the return value of
gpiod_get_from_of_node() as is and fix the bug in
devm_fwnode_get_index_gpiod_from_child(). Other callers would still need
to be reworked. The effort would be the same as with the chosen solution.

Signed-off-by: Georg Waibel <georg.waibel@sensor-technik.de>
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/gpio/gpiolib.c
drivers/regulator/da9211-regulator.c
drivers/regulator/s2mps11.c
drivers/regulator/s5m8767.c
drivers/regulator/tps65090-regulator.c

index e013d417a9361c5d19f340bf7a69ce2627781519..be1d1d2f8aaa4c8d5d5e195d60343748b66b6598 100644 (file)
@@ -4244,8 +4244,7 @@ EXPORT_SYMBOL_GPL(gpiod_get_index);
  *
  * Returns:
  * On successful request the GPIO pin is configured in accordance with
- * provided @dflags. If the node does not have the requested GPIO
- * property, NULL is returned.
+ * provided @dflags.
  *
  * In case of error an ERR_PTR() is returned.
  */
@@ -4267,9 +4266,6 @@ struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
                                        index, &flags);
 
        if (!desc || IS_ERR(desc)) {
-               /* If it is not there, just return NULL */
-               if (PTR_ERR(desc) == -ENOENT)
-                       return NULL;
                return desc;
        }
 
index da37b4ccd834b94cb8b3b7fe2ee0c9d0ddd19be1..0309823d2c726035b0598b09b3add990c35a8363 100644 (file)
@@ -289,6 +289,8 @@ static struct da9211_pdata *da9211_parse_regulators_dt(
                                  0,
                                  GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
                                  "da9211-enable");
+               if (IS_ERR(pdata->gpiod_ren[n]))
+                       pdata->gpiod_ren[n] = NULL;
                n++;
        }
 
index 9c06ecd80a90403d0af6b620e92fdfe61b6e6ad0..e5a74ae4068704abe67abdd28bee8524a56cd211 100644 (file)
@@ -843,7 +843,9 @@ static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
                                0,
                                GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
                                "s2mps11-regulator");
-               if (IS_ERR(gpio[reg])) {
+               if (PTR_ERR(gpio[reg]) == -ENOENT)
+                       gpio[reg] = NULL;
+               else if (IS_ERR(gpio[reg])) {
                        dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n",
                                reg, rdata[reg].name);
                        continue;
index bb9d1a083299fc02b6aba71cc7e8ca7f17843c57..6ca27e9d5ef7d3981d4ab4ec6b5bc45f854076d9 100644 (file)
@@ -574,7 +574,9 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
                        0,
                        GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
                        "s5m8767");
-               if (IS_ERR(rdata->ext_control_gpiod))
+               if (PTR_ERR(rdata->ext_control_gpiod) == -ENOENT)
+                       rdata->ext_control_gpiod = NULL;
+               else if (IS_ERR(rdata->ext_control_gpiod))
                        return PTR_ERR(rdata->ext_control_gpiod);
 
                rdata->id = i;
index ca39b3d55123913e0da70be92f5926826bec8da7..10ea4b5a0f55747a45c4a1d7c788b7b2080211bf 100644 (file)
@@ -371,11 +371,12 @@ static struct tps65090_platform_data *tps65090_parse_dt_reg_data(
                                                                    "dcdc-ext-control-gpios", 0,
                                                                    gflags,
                                                                    "tps65090");
-                       if (IS_ERR(rpdata->gpiod))
-                               return ERR_CAST(rpdata->gpiod);
-                       if (!rpdata->gpiod)
+                       if (PTR_ERR(rpdata->gpiod) == -ENOENT) {
                                dev_err(&pdev->dev,
                                        "could not find DCDC external control GPIO\n");
+                               rpdata->gpiod = NULL;
+                       } else if (IS_ERR(rpdata->gpiod))
+                               return ERR_CAST(rpdata->gpiod);
                }
 
                if (of_property_read_u32(tps65090_matches[idx].of_node,