[PATCH v3 2/2] leds: tca6507: Turn the LEDs off on unbind
From: Danish Khateeb
Date: Wed Oct 28 2026 - 13:59:58 EST
Unregistering an LED that is on turns it off, and the driver does that
from its work, which is queued from led_assign(). On unbind the work is
then cancelled by devres, so if it has not run yet the LED stays on after
the driver is gone.
Flush the work instead of cancelling it. By the time the devres action
runs, the LEDs and the GPIO chip have been unregistered, and the work
does not queue itself, so nothing can queue it again.
Signed-off-by: Danish Khateeb <danishkhateeb03@xxxxxxxxx>
---
drivers/leds/leds-tca6507.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/leds/leds-tca6507.c b/drivers/leds/leds-tca6507.c
index 0f987e551f03..ffad476af625 100644
--- a/drivers/leds/leds-tca6507.c
+++ b/drivers/leds/leds-tca6507.c
@@ -71,7 +71,6 @@
* not recognised when matching.
*/
-#include <linux/devm-helpers.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/leds.h>
@@ -712,6 +711,11 @@ static const struct of_device_id __maybe_unused of_tca6507_leds_match[] = {
};
MODULE_DEVICE_TABLE(of, of_tca6507_leds_match);
+static void tca6507_flush_work(void *work)
+{
+ flush_work(work);
+}
+
static int tca6507_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
@@ -738,7 +742,8 @@ static int tca6507_probe(struct i2c_client *client)
tca->client = client;
spin_lock_init(&tca->lock);
- err = devm_work_autocancel(dev, &tca->work, tca6507_work);
+ INIT_WORK(&tca->work, tca6507_work);
+ err = devm_add_action_or_reset(dev, tca6507_flush_work, &tca->work);
if (err)
return err;
--
2.56.0