[PATCH 21/21] leds: lm3692x: Use devm_mutex_init() to avoid premature mutex destruction

From: Lee Jones

Date: Wed Oct 21 2026 - 08:52:11 EST


lm3692x_probe() registers the LED class device using
devm_led_classdev_register_ext(), so the LED is unregistered during
devres release after lm3692x_remove() returns. Calling mutex_destroy()
in lm3692x_remove() destroys led->lock while the LED sysfs interface is
still active and before devres unregistration turns off the LED via
lm3692x_brightness_set().

Initialise led->lock with devm_mutex_init() before registering the LED
class device and drop mutex_destroy() from lm3692x_remove() so the mutex
outlives the LED device.

Fixes: 9699cb6bbef2 ("leds: lm3692x: Introduce LM3692x dual string driver")
Closes: https://sashiko.dev/#/bug/linux-012e3698-2af6-4390-88c9-d8989d2dc2a6
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/leds/leds-lm3692x.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/leds-lm3692x.c b/drivers/leds/leds-lm3692x.c
index 9c58d54c5783..ec53f9d25654 100644
--- a/drivers/leds/leds-lm3692x.c
+++ b/drivers/leds/leds-lm3692x.c
@@ -470,7 +470,10 @@ static int lm3692x_probe(struct i2c_client *client)
if (!led)
return -ENOMEM;

- mutex_init(&led->lock);
+ ret = devm_mutex_init(&client->dev, &led->lock);
+ if (ret)
+ return ret;
+
led->client = client;
led->led_dev.brightness_set_blocking = lm3692x_brightness_set;
led->model_id = id->driver_data;
@@ -500,7 +503,6 @@ static void lm3692x_remove(struct i2c_client *client)
struct lm3692x_led *led = i2c_get_clientdata(client);

lm3692x_leds_disable(led);
- mutex_destroy(&led->lock);
}

static const struct i2c_device_id lm3692x_id[] = {
--
2.56.0.218.g1ec904b173-goog