Skip to content

Commit 5ac50ec

Browse files
andy-shevlag-linaro
authored andcommitted
leds: gpio: Refactor code to use devm_gpiod_get_index_optional()
Instead of checking for the specific error codes, replace devm_gpiod_get_index() with devm_gpiod_get_index_optional(). In this case we just return all errors to the caller and simply check for NULL in case if legacy GPIO is being used. As the result the code is easier to read and maintain. Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent f5ad594 commit 5ac50ec

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/leds/leds-gpio.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,13 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx,
218218
* device, this will hit the board file, if any and get
219219
* the GPIO from there.
220220
*/
221-
gpiod = devm_gpiod_get_index(dev, NULL, idx, GPIOD_OUT_LOW);
222-
if (!IS_ERR(gpiod)) {
221+
gpiod = devm_gpiod_get_index_optional(dev, NULL, idx, GPIOD_OUT_LOW);
222+
if (IS_ERR(gpiod))
223+
return gpiod;
224+
if (gpiod) {
223225
gpiod_set_consumer_name(gpiod, template->name);
224226
return gpiod;
225227
}
226-
if (PTR_ERR(gpiod) != -ENOENT)
227-
return gpiod;
228228

229229
/*
230230
* This is the legacy code path for platform code that

0 commit comments

Comments
 (0)