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

Andy Shevchenko
2026-05-05T13:25:15Z

On Tue, May 05, 2026 at 04:19:36PM +0300, Andy Shevchenko wrote:
> 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:

...

> > >> + 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;
> > }

To be clear

struct gpio_desc *gpiod;

gpiod = devm_gpiod_get_index_optional(dev, NULL, idx, GPIOD_OUT_LOW);
if (!IS_ERR(gpiod))
gpiod_set_consumer_name(gpiod, template->name);

return gpiod;

But looking at the original code, I would leave another return, so

gpiod = devm_gpiod_get_index_optional(dev, NULL, idx, GPIOD_OUT_LOW);
if (IS_ERR(gpiod))
return gpiod;

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

Nope, the con_id != consumer name. Can't be done this way.

> > simplification.

--
With Best Regards,
Andy Shevchenko