Skip to content

Commit 025bf37

Browse files
Waibel Georgbroonie
authored andcommitted
gpio: Fix return value mismatch of function gpiod_get_from_of_node()
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 <[email protected]> Reviewed-by: Krzysztof Kozlowski <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 65d80db commit 025bf37

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

drivers/gpio/gpiolib.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4244,8 +4244,7 @@ EXPORT_SYMBOL_GPL(gpiod_get_index);
42444244
*
42454245
* Returns:
42464246
* On successful request the GPIO pin is configured in accordance with
4247-
* provided @dflags. If the node does not have the requested GPIO
4248-
* property, NULL is returned.
4247+
* provided @dflags.
42494248
*
42504249
* In case of error an ERR_PTR() is returned.
42514250
*/
@@ -4267,9 +4266,6 @@ struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
42674266
index, &flags);
42684267

42694268
if (!desc || IS_ERR(desc)) {
4270-
/* If it is not there, just return NULL */
4271-
if (PTR_ERR(desc) == -ENOENT)
4272-
return NULL;
42734269
return desc;
42744270
}
42754271

drivers/regulator/da9211-regulator.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ static struct da9211_pdata *da9211_parse_regulators_dt(
289289
0,
290290
GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
291291
"da9211-enable");
292+
if (IS_ERR(pdata->gpiod_ren[n]))
293+
pdata->gpiod_ren[n] = NULL;
292294
n++;
293295
}
294296

drivers/regulator/s2mps11.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,9 @@ static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
843843
0,
844844
GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
845845
"s2mps11-regulator");
846-
if (IS_ERR(gpio[reg])) {
846+
if (PTR_ERR(gpio[reg]) == -ENOENT)
847+
gpio[reg] = NULL;
848+
else if (IS_ERR(gpio[reg])) {
847849
dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n",
848850
reg, rdata[reg].name);
849851
continue;

drivers/regulator/s5m8767.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,9 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
574574
0,
575575
GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
576576
"s5m8767");
577-
if (IS_ERR(rdata->ext_control_gpiod))
577+
if (PTR_ERR(rdata->ext_control_gpiod) == -ENOENT)
578+
rdata->ext_control_gpiod = NULL;
579+
else if (IS_ERR(rdata->ext_control_gpiod))
578580
return PTR_ERR(rdata->ext_control_gpiod);
579581

580582
rdata->id = i;

drivers/regulator/tps65090-regulator.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,12 @@ static struct tps65090_platform_data *tps65090_parse_dt_reg_data(
371371
"dcdc-ext-control-gpios", 0,
372372
gflags,
373373
"tps65090");
374-
if (IS_ERR(rpdata->gpiod))
375-
return ERR_CAST(rpdata->gpiod);
376-
if (!rpdata->gpiod)
374+
if (PTR_ERR(rpdata->gpiod) == -ENOENT) {
377375
dev_err(&pdev->dev,
378376
"could not find DCDC external control GPIO\n");
377+
rpdata->gpiod = NULL;
378+
} else if (IS_ERR(rpdata->gpiod))
379+
return ERR_CAST(rpdata->gpiod);
379380
}
380381

381382
if (of_property_read_u32(tps65090_matches[idx].of_node,

0 commit comments

Comments
 (0)