Re: [PATCH v2 2/2] leds: class: Reinitialise list after dropping from lookup table

From: Lee Jones

Date: Thu Apr 09 2026 - 12:01:03 EST


On Tue, 31 Mar 2026, Andy Shevchenko wrote:

> Currently the lookup table just removes the list entry and leaves
> the stale pointers in it. If the lookup is embedded in some data
> structure, the pointer to the lookup entry can't be NULL (always
> valid), but calling led_remove_lookup() on it twice will lead to
> the wrong behaviour. To avoid that the user has to track the state
> itself. With this change in place, the user may drop that approach
> and use something like
>
> probe:
> INIT_LIST_HEAD(&lookup.list);
> if (LED lookup is required)
> led_add_lookup(&lookup);
>
> remove:
> led_remove_lookup(&lookup);

How do we feel about a devm_led_add_lookup()?

> without any additional tracking kept over the device lifetime.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> ---
> drivers/leds/led-class.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
> index b53ebe3a0faa..424c07e0ecce 100644
> --- a/drivers/leds/led-class.c
> +++ b/drivers/leds/led-class.c
> @@ -425,7 +425,7 @@ void led_remove_lookup(struct led_lookup_data *led_lookup)
> return;
>
> mutex_lock(&leds_lookup_lock);
> - list_del(&led_lookup->list);
> + list_del_init(&led_lookup->list);
> mutex_unlock(&leds_lookup_lock);
> }
> EXPORT_SYMBOL_GPL(led_remove_lookup);
> --
> 2.50.1
>

--
Lee Jones [李琼斯]