Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds: mlxreg: Use devm_mutex_init() for mutex initialization

In this driver LEDs are registered using devm_led_classdev_register()
so they are automatically unregistered after module's remove() is done.
led_classdev_unregister() calls module's led_set_brightness() to turn off
the LEDs and that callback uses mutex which was destroyed already
in module's remove() so use devm API instead.

Signed-off-by: George Stark <gnstark@salutedevices.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20240411161032.609544-8-gnstark@salutedevices.com
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

George Stark and committed by
Lee Jones
efc347b9 310d2652

+5 -9
+5 -9
drivers/leds/leds-mlxreg.c
··· 256 256 { 257 257 struct mlxreg_core_platform_data *led_pdata; 258 258 struct mlxreg_led_priv_data *priv; 259 + int err; 259 260 260 261 led_pdata = dev_get_platdata(&pdev->dev); 261 262 if (!led_pdata) { ··· 268 267 if (!priv) 269 268 return -ENOMEM; 270 269 271 - mutex_init(&priv->access_lock); 270 + err = devm_mutex_init(&pdev->dev, &priv->access_lock); 271 + if (err) 272 + return err; 273 + 272 274 priv->pdev = pdev; 273 275 priv->pdata = led_pdata; 274 276 275 277 return mlxreg_led_config(priv); 276 - } 277 - 278 - static void mlxreg_led_remove(struct platform_device *pdev) 279 - { 280 - struct mlxreg_led_priv_data *priv = dev_get_drvdata(&pdev->dev); 281 - 282 - mutex_destroy(&priv->access_lock); 283 278 } 284 279 285 280 static struct platform_driver mlxreg_led_driver = { ··· 283 286 .name = "leds-mlxreg", 284 287 }, 285 288 .probe = mlxreg_led_probe, 286 - .remove_new = mlxreg_led_remove, 287 289 }; 288 290 289 291 module_platform_driver(mlxreg_led_driver);