Re: [PATCH] [v2] leds: gpio: make legacy gpiolib interface optional

Andy Shevchenko
2026-05-05T13:22:03Z

On Tue, May 05, 2026 at 03:10:28PM +0200, Arnd Bergmann wrote:
> On Mon, May 4, 2026, at 09:31, Andy Shevchenko wrote:
> > On Thu, Apr 30, 2026 at 11:11:55AM +0200, Arnd Bergmann wrote:
> >> - /*
> >> - * This is the legacy code path for platform code that
> >> - * still uses GPIO numbers. Ultimately we would like to get
> >> - * rid of this block completely.
> >> - */
> >> + return gpiod;
> >
> > Do we need to repeat the upper `return gpiod;` statement? With this split
> > I don't see that we need to have two repetitive return statements.
>
> Right, I've simplified this now to
>
> static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx,
> const struct gpio_led *template)
> {
> struct gpio_desc *gpiod;
>
> gpiod = devm_gpiod_get_index_optional(dev, NULL, idx, GPIOD_OUT_LOW);

> if (gpiod && !IS_ERR(gpiod));

And this is not needed. The below is NULL-aware.

> gpiod_set_consumer_name(gpiod, template->name);
>
> return gpiod;
> }
>
> which still keeps the existing behavior but is a bit more compact.
>
> I think we can actually just remove that function altogether
> and just pass the name into devm_gpiod_get_index_optional()
> from the caller like
>
> gpiod = devm_gpiod_get_index_optional(dev, template->name, i, GPIOD_OUT_LOW);
>
> Did I get that right? If so, I'll fold that in as another
> simplification.

--
With Best Regards,
Andy Shevchenko