leds: gpio: Refactor code to use devm_gpiod_get_index_optional()
JIRA: https://issues.redhat.com/browse/RHEL-43483 commit 5ac50ec712921f6250188732387bf5dac33736ae Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Date: Mon Oct 16 19:10:02 2023 +0300 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 <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20231016161005.1471768-3-andriy.shevchenko@linux.intel.com Signed-off-by: Lee Jones <lee@kernel.org> Signed-off-by: Radu Rendec <rrendec@redhat.com>
This commit is contained in:
parent
0ec841933c
commit
ae5f87bb9b
|
@ -218,13 +218,13 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx,
|
|||
* device, this will hit the board file, if any and get
|
||||
* the GPIO from there.
|
||||
*/
|
||||
gpiod = devm_gpiod_get_index(dev, NULL, idx, GPIOD_OUT_LOW);
|
||||
if (!IS_ERR(gpiod)) {
|
||||
gpiod = devm_gpiod_get_index_optional(dev, NULL, idx, GPIOD_OUT_LOW);
|
||||
if (IS_ERR(gpiod))
|
||||
return gpiod;
|
||||
if (gpiod) {
|
||||
gpiod_set_consumer_name(gpiod, template->name);
|
||||
return gpiod;
|
||||
}
|
||||
if (PTR_ERR(gpiod) != -ENOENT)
|
||||
return gpiod;
|
||||
|
||||
/*
|
||||
* This is the legacy code path for platform code that
|
||||
|
|
Loading…
Reference in New Issue