public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Lee Jones <lee@kernel.org>, Pavel Machek <pavel@kernel.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v2 2/2] leds: class: Reinitialise list after dropping from lookup table
Date: Tue, 31 Mar 2026 20:28:29 +0200	[thread overview]
Message-ID: <20260331183055.1209526-3-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20260331183055.1209526-1-andriy.shevchenko@linux.intel.com>

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);

without any additional tracking kept over the device lifetime.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 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


  parent reply	other threads:[~2026-03-31 18:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31 18:28 [PATCH v2 0/2] leds: class: improve led_remove_lookup() Andy Shevchenko
2026-03-31 18:28 ` [PATCH v2 1/2] leds: class: Make led_remove_lookup() NULL-aware Andy Shevchenko
2026-03-31 18:28 ` Andy Shevchenko [this message]
2026-04-09 15:52   ` [PATCH v2 2/2] leds: class: Reinitialise list after dropping from lookup table Lee Jones
2026-04-09 16:00     ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260331183055.1209526-3-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox