[PATCH 7/8] leds: lp3952: explicitly unregister LEDs at module's shutdown

George Stark gnstark at salutedevices.com
Thu Oct 26 00:07:36 AEDT 2023


LEDs are registered using devm_led_classdev_register() and automatically
unregistered after module's remove(). led_classdev_unregister() calls
led_set_brightness() to turn off the LEDs and module's appropriate callback
uses resources those were destroyed already in module's remove().
So explicitly unregister LEDs at module shutdown.

Signed-off-by: George Stark <gnstark at salutedevices.com>
---
 drivers/leds/leds-lp3952.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/leds/leds-lp3952.c b/drivers/leds/leds-lp3952.c
index 3bd55652a706..2de49192011a 100644
--- a/drivers/leds/leds-lp3952.c
+++ b/drivers/leds/leds-lp3952.c
@@ -257,8 +257,13 @@ static int lp3952_probe(struct i2c_client *client)
 static void lp3952_remove(struct i2c_client *client)
 {
 	struct lp3952_led_array *priv;
+	int i;
 
 	priv = i2c_get_clientdata(client);
+	for (i = 0; i < LP3952_LED_ALL; i++)
+		if (priv->leds[i].priv)
+			devm_led_classdev_unregister(&client->dev,
+						     &priv->leds[i].cdev);
 	lp3952_on_off(priv, LP3952_LED_ALL, false);
 	gpiod_set_value(priv->enable_gpio, 0);
 }
-- 
2.38.4



More information about the Linuxppc-dev mailing list