Linux LED subsystem development
 help / color / mirror / Atom feed
From: kr494167@gmail.com
To: lee@kernel.org, pavel@kernel.org
Cc: s.trumtrar@pengutronix.de, linux-leds@vger.kernel.org,
	linux-kernel@vger.kernel.org, surendra <kr494167@gmail.com>
Subject: [PATCH] leds: lp5860: fix LED teardown ordering
Date: Mon, 20 Jul 2026 16:18:55 +0530	[thread overview]
Message-ID: <20260720104855.98186-1-kr494167@gmail.com> (raw)

From: surendra <kr494167@gmail.com>

The driver disables the chip from its remove callback before devres
unregisters the LEDs. LED unregistration turns the LEDs off through the
driver brightness callback, which can then access disabled hardware.

Unregister the LEDs before disabling the chip, including when probe fails
after some LEDs have been registered. Keep track of registered LEDs so the
devres actions can be released explicitly.

Also remove the early mutex destruction from the SPI remove callback:
hardware teardown takes the same mutex.

Fixes: f0a66563aa2d ("leds: Add support for TI LP5860 LED driver chip")
Signed-off-by: surendra <kr494167@gmail.com>
---
 drivers/leds/rgb/leds-lp5860-core.c | 13 ++++++++++---
 drivers/leds/rgb/leds-lp5860-spi.c  |  4 ----
 drivers/leds/rgb/leds-lp5860.h      |  1 +
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/leds/rgb/leds-lp5860-core.c b/drivers/leds/rgb/leds-lp5860-core.c
index 75498311b080..9646d3985239 100644
--- a/drivers/leds/rgb/leds-lp5860-core.c
+++ b/drivers/leds/rgb/leds-lp5860-core.c
@@ -149,12 +149,11 @@ static int lp5860_init_dt(struct lp5860 *lp)
 	struct led_classdev *led_cdev;
 	struct mc_subled *mc_led_info;
 	struct lp5860_led *led;
-	int led_index = 0;
 	int chan;
 	int ret;
 
 	device_for_each_child_node_scoped(lp->dev, multi_led) {
-		led = &lp->leds[led_index];
+		led = &lp->leds[lp->num_leds];
 
 		init_data.fwnode = multi_led;
 
@@ -188,12 +187,18 @@ static int lp5860_init_dt(struct lp5860 *lp)
 		if (ret)
 			return dev_err_probe(lp->dev, ret, "%pfwP: Failed to register Multi-Color LEDs\n",
 					     multi_led);
-		led_index++;
+		lp->num_leds++;
 	}
 
 	return 0;
 }
 
+static void lp5860_unregister_leds(struct lp5860 *lp)
+{
+	while (lp->num_leds)
+		devm_led_classdev_multicolor_unregister(lp->dev, &lp->leds[--lp->num_leds].mc_cdev);
+}
+
 int lp5860_device_init(struct device *dev)
 {
 	struct lp5860 *lp = dev_get_drvdata(dev);
@@ -221,6 +226,7 @@ int lp5860_device_init(struct device *dev)
 	return 0;
 
 err_disable:
+	lp5860_unregister_leds(lp);
 	lp5860_chip_enable(lp, LP5860_CHIP_DISABLE);
 	return ret;
 }
@@ -230,6 +236,7 @@ void lp5860_device_remove(struct device *dev)
 {
 	struct lp5860 *lp = dev_get_drvdata(dev);
 
+	lp5860_unregister_leds(lp);
 	lp5860_chip_enable(lp, LP5860_CHIP_DISABLE);
 }
 EXPORT_SYMBOL_GPL(lp5860_device_remove);
diff --git a/drivers/leds/rgb/leds-lp5860-spi.c b/drivers/leds/rgb/leds-lp5860-spi.c
index 5e0c44854a68..e1565eac90f9 100644
--- a/drivers/leds/rgb/leds-lp5860-spi.c
+++ b/drivers/leds/rgb/leds-lp5860-spi.c
@@ -70,10 +70,6 @@ static int lp5860_probe(struct spi_device *spi)
 
 static void lp5860_remove(struct spi_device *spi)
 {
-	struct lp5860 *lp5860 = spi_get_drvdata(spi);
-
-	mutex_destroy(&lp5860->lock);
-
 	lp5860_device_remove(&spi->dev);
 }
 
diff --git a/drivers/leds/rgb/leds-lp5860.h b/drivers/leds/rgb/leds-lp5860.h
index 940be0c6e8da..ce30fb5596c0 100644
--- a/drivers/leds/rgb/leds-lp5860.h
+++ b/drivers/leds/rgb/leds-lp5860.h
@@ -258,6 +258,7 @@ struct lp5860 {
 	struct device *dev;
 	struct regmap *regmap;
 	struct mutex lock;
+	unsigned int num_leds;
 
 	DECLARE_FLEX_ARRAY(struct lp5860_led, leds);
 };
-- 
2.55.0


                 reply	other threads:[~2026-07-20 10:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260720104855.98186-1-kr494167@gmail.com \
    --to=kr494167@gmail.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@kernel.org \
    --cc=s.trumtrar@pengutronix.de \
    /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