mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] leds: gpio: Skip unavailable LEDs during shutdown
@ 2026-07-10 15:08 Steve Dunnagan
  2026-07-23 11:35 ` Lee Jones
  2026-07-24 18:04 ` [PATCH v2] leds: gpio: Clear error pointers for skipped LEDs Steve Dunnagan
  0 siblings, 2 replies; 6+ messages in thread
From: Steve Dunnagan @ 2026-07-10 15:08 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek
  Cc: Jacek Anaszewski, Linus Walleij, linux-leds, linux-kernel

gpio_led_probe() leaves an error-valued GPIO descriptor in the LED
data when an unavailable platform-data LED is skipped.

The entry remains included in priv->num_leds, so gpio_led_shutdown()
later passes the error pointer to gpio_led_set(), producing:

gpiod_set_value: invalid GPIO (errorpointer: -ENOENT)

Skip entries with error-valued GPIO descriptors during shutdown.

Fixes: 45d4c6de4e49 ("leds: gpio: Try to lookup gpiod from device")
Assisted-by: ChatGPT:GPT-5.5-Thinking
Signed-off-by: Steve Dunnagan <sdunnaga@redhat.com>
---
 drivers/leds/leds-gpio.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index 8ae71c2e91e0..63cb517ef385 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -304,6 +304,9 @@ static void gpio_led_shutdown(struct platform_device *pdev)
 	for (i = 0; i < priv->num_leds; i++) {
 		struct gpio_led_data *led = &priv->leds[i];
 
+		if (IS_ERR(led->gpiod))
+			continue;
+
 		if (!(led->cdev.flags & LED_RETAIN_AT_SHUTDOWN))
 			gpio_led_set(&led->cdev, LED_OFF);
 	}
-- 
2.49.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] leds: gpio: Skip unavailable LEDs during shutdown
  2026-07-10 15:08 [PATCH] leds: gpio: Skip unavailable LEDs during shutdown Steve Dunnagan
@ 2026-07-23 11:35 ` Lee Jones
  2026-07-24 18:04 ` [PATCH v2] leds: gpio: Clear error pointers for skipped LEDs Steve Dunnagan
  1 sibling, 0 replies; 6+ messages in thread
From: Lee Jones @ 2026-07-23 11:35 UTC (permalink / raw)
  To: Steve Dunnagan
  Cc: Pavel Machek, Jacek Anaszewski, Linus Walleij, linux-leds, linux-kernel

On Fri, 10 Jul 2026, Steve Dunnagan wrote:

> gpio_led_probe() leaves an error-valued GPIO descriptor in the LED
> data when an unavailable platform-data LED is skipped.

So why not nip that in the bud and fix that instead?

> The entry remains included in priv->num_leds, so gpio_led_shutdown()
> later passes the error pointer to gpio_led_set(), producing:
> 
> gpiod_set_value: invalid GPIO (errorpointer: -ENOENT)
> 
> Skip entries with error-valued GPIO descriptors during shutdown.
> 
> Fixes: 45d4c6de4e49 ("leds: gpio: Try to lookup gpiod from device")
> Assisted-by: ChatGPT:GPT-5.5-Thinking
> Signed-off-by: Steve Dunnagan <sdunnaga@redhat.com>
> ---
>  drivers/leds/leds-gpio.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
> index 8ae71c2e91e0..63cb517ef385 100644
> --- a/drivers/leds/leds-gpio.c
> +++ b/drivers/leds/leds-gpio.c
> @@ -304,6 +304,9 @@ static void gpio_led_shutdown(struct platform_device *pdev)
>  	for (i = 0; i < priv->num_leds; i++) {
>  		struct gpio_led_data *led = &priv->leds[i];
>  
> +		if (IS_ERR(led->gpiod))
> +			continue;
> +
>  		if (!(led->cdev.flags & LED_RETAIN_AT_SHUTDOWN))
>  			gpio_led_set(&led->cdev, LED_OFF);
>  	}
> -- 
> 2.49.0
> 

-- 
Lee Jones

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] leds: gpio: Clear error pointers for skipped LEDs
  2026-07-10 15:08 [PATCH] leds: gpio: Skip unavailable LEDs during shutdown Steve Dunnagan
  2026-07-23 11:35 ` Lee Jones
@ 2026-07-24 18:04 ` Steve Dunnagan
  2026-07-25 14:02   ` Linus Walleij
                     ` (2 more replies)
  1 sibling, 3 replies; 6+ messages in thread
From: Steve Dunnagan @ 2026-07-24 18:04 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek
  Cc: Jacek Anaszewski, Linus Walleij, linux-leds, linux-kernel

gpio_led_get_gpiod() returns an error pointer when a platform-data
LED's GPIO is unavailable. gpio_led_probe() skips registration in that
case, but leaves the error pointer in led_dat->gpiod.

The skipped entry remains included in priv->num_leds. During shutdown,
gpio_led_shutdown() walks those entries and passes the error pointer to
gpio_led_set(), producing:

  gpiod_set_value: invalid GPIO (errorpointer: -ENOENT)

Clear led_dat->gpiod before skipping the LED so skipped entries do not
retain error-valued descriptors.

Fixes: 45d4c6de4e49 ("leds: gpio: Try to lookup gpiod from device")
Suggested-by: Lee Jones <lee@kernel.org>
Assisted-by: ChatGPT:GPT-5.5-Thinking
Signed-off-by: Steve Dunnagan <sdunnaga@redhat.com>
---
Changes in v2:
- Clear led_dat->gpiod in the probe skip path instead of checking for
  error-valued descriptors during shutdown, as suggested by Lee.

Tested on an Orange Pi 5 Plus running Fedora 42 with a test platform
device containing an unavailable GPIO LED. Before the fix, reboot
logged:

  gpiod_set_value: invalid GPIO (errorpointer: -ENOENT)

After the fix, the LED was still skipped during probe, but reboot
completed without the invalid-GPIO warning.

 drivers/leds/leds-gpio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index 8ae71c2e91e0..8810fdcf2d77 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -277,6 +277,7 @@ static int gpio_led_probe(struct platform_device *pdev)
 			if (IS_ERR(led_dat->gpiod)) {
 				dev_info(dev, "Skipping unavailable LED gpio %d (%s)\n",
 					 template->gpio, template->name);
+				led_dat->gpiod = NULL;
 				continue;
 			}
 
-- 
2.55.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] leds: gpio: Clear error pointers for skipped LEDs
  2026-07-24 18:04 ` [PATCH v2] leds: gpio: Clear error pointers for skipped LEDs Steve Dunnagan
@ 2026-07-25 14:02   ` Linus Walleij
  2026-08-06 13:52   ` (subset) " Lee Jones
  2026-08-13 15:45   ` Steve Dunnagan
  2 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2026-07-25 14:02 UTC (permalink / raw)
  To: Steve Dunnagan
  Cc: Lee Jones, Pavel Machek, Jacek Anaszewski, linux-leds, linux-kernel

On Fri, Jul 24, 2026 at 8:04 PM Steve Dunnagan <sdunnaga@redhat.com> wrote:

> gpio_led_get_gpiod() returns an error pointer when a platform-data
> LED's GPIO is unavailable. gpio_led_probe() skips registration in that
> case, but leaves the error pointer in led_dat->gpiod.
>
> The skipped entry remains included in priv->num_leds. During shutdown,
> gpio_led_shutdown() walks those entries and passes the error pointer to
> gpio_led_set(), producing:
>
>   gpiod_set_value: invalid GPIO (errorpointer: -ENOENT)
>
> Clear led_dat->gpiod before skipping the LED so skipped entries do not
> retain error-valued descriptors.
>
> Fixes: 45d4c6de4e49 ("leds: gpio: Try to lookup gpiod from device")
> Suggested-by: Lee Jones <lee@kernel.org>
> Assisted-by: ChatGPT:GPT-5.5-Thinking
> Signed-off-by: Steve Dunnagan <sdunnaga@redhat.com>

Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: (subset) [PATCH v2] leds: gpio: Clear error pointers for skipped LEDs
  2026-07-24 18:04 ` [PATCH v2] leds: gpio: Clear error pointers for skipped LEDs Steve Dunnagan
  2026-07-25 14:02   ` Linus Walleij
@ 2026-08-06 13:52   ` Lee Jones
  2026-08-13 15:45   ` Steve Dunnagan
  2 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2026-08-06 13:52 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek, Steve Dunnagan
  Cc: Jacek Anaszewski, Linus Walleij, linux-leds, linux-kernel

On Fri, 24 Jul 2026 14:04:12 -0400, Steve Dunnagan wrote:
> gpio_led_get_gpiod() returns an error pointer when a platform-data
> LED's GPIO is unavailable. gpio_led_probe() skips registration in that
> case, but leaves the error pointer in led_dat->gpiod.
> 
> The skipped entry remains included in priv->num_leds. During shutdown,
> gpio_led_shutdown() walks those entries and passes the error pointer to
> gpio_led_set(), producing:
> 
> [...]

Applied, thanks!

[1/1] leds: gpio: Clear error pointers for skipped LEDs
      commit: 942901eeda934f1bebf2605a781155e9d6bc7f6e

--
Lee Jones [李琼斯]


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] leds: gpio: Clear error pointers for skipped LEDs
  2026-07-24 18:04 ` [PATCH v2] leds: gpio: Clear error pointers for skipped LEDs Steve Dunnagan
  2026-07-25 14:02   ` Linus Walleij
  2026-08-06 13:52   ` (subset) " Lee Jones
@ 2026-08-13 15:45   ` Steve Dunnagan
  2 siblings, 0 replies; 6+ messages in thread
From: Steve Dunnagan @ 2026-08-13 15:45 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek
  Cc: Linus Walleij, Jacek Anaszewski, linux-leds, linux-kernel

Hi Lee, Pavel,

Just checking whether anything else is needed for this v2.

Linus Walleij replied with:

  Reviewed-by: Linus Walleij <linusw@kernel.org>

Thanks,
Steve


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-08-13 15:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-10 15:08 [PATCH] leds: gpio: Skip unavailable LEDs during shutdown Steve Dunnagan
2026-07-23 11:35 ` Lee Jones
2026-07-24 18:04 ` [PATCH v2] leds: gpio: Clear error pointers for skipped LEDs Steve Dunnagan
2026-07-25 14:02   ` Linus Walleij
2026-08-06 13:52   ` (subset) " Lee Jones
2026-08-13 15:45   ` Steve Dunnagan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®