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 <gnst...@salutedevices.com>
---
 drivers/leds/leds-mlxreg.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/leds-mlxreg.c b/drivers/leds/leds-mlxreg.c
index b7855c93bd72..6d65e39c3372 100644
--- a/drivers/leds/leds-mlxreg.c
+++ b/drivers/leds/leds-mlxreg.c
@@ -258,6 +258,7 @@ static int mlxreg_led_probe(struct platform_device *pdev)
 {
        struct mlxreg_core_platform_data *led_pdata;
        struct mlxreg_led_priv_data *priv;
+       int res;
 
        led_pdata = dev_get_platdata(&pdev->dev);
        if (!led_pdata) {
@@ -273,13 +274,22 @@ static int mlxreg_led_probe(struct platform_device *pdev)
        priv->pdev = pdev;
        priv->pdata = led_pdata;
 
-       return mlxreg_led_config(priv);
+       if (!devres_open_group(&pdev->dev, priv, GFP_KERNEL))
+               return -ENOMEM;
+
+       res = mlxreg_led_config(priv);
+       if (res)
+               devres_remove_group(&pdev->dev, priv);
+
+       return res;
 }
 
 static int mlxreg_led_remove(struct platform_device *pdev)
 {
        struct mlxreg_led_priv_data *priv = dev_get_drvdata(&pdev->dev);
 
+       devres_release_group(&pdev->dev, priv);
+
        mutex_destroy(&priv->access_lock);
 
        return 0;
-- 
2.38.4

Reply via email to