diff mbox series

[08/13] leds: mlxreg: Fix devm vs. non-devm ordering

Message ID 1667983694-15040-9-git-send-email-wangyufen@huawei.com
State New
Headers show
Series leds: Fix devm vs. non-devm ordering | expand

Commit Message

wangyufen Nov. 9, 2022, 8:48 a.m. UTC
When non-devm resources are allocated they mustn't be followed by devm
allocations, otherwise it will break the tear down ordering and might
lead to crashes or other bugs during ->remove() stage. Fix this by
wrapping mutex_destroy() call with devm_add_action_or_reset().

Fixes: 386570d76f2f ("leds: add driver for support Mellanox regmap LEDs for BMC and x86 platform")
Signed-off-by: Wang Yufen <wangyufen@huawei.com>
Cc: Vadim Pasternak <vadimp@mellanox.com>
---
 drivers/leds/leds-mlxreg.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/drivers/leds/leds-mlxreg.c b/drivers/leds/leds-mlxreg.c
index b7855c9..b7c58fb 100644
--- a/drivers/leds/leds-mlxreg.c
+++ b/drivers/leds/leds-mlxreg.c
@@ -254,10 +254,16 @@  static int mlxreg_led_config(struct mlxreg_led_priv_data *priv)
 	return 0;
 }
 
+static void mlxreg_led_mutex_destroy(void *lock)
+{
+	mutex_destroy(lock);
+}
+
 static int mlxreg_led_probe(struct platform_device *pdev)
 {
 	struct mlxreg_core_platform_data *led_pdata;
 	struct mlxreg_led_priv_data *priv;
+	int ret;
 
 	led_pdata = dev_get_platdata(&pdev->dev);
 	if (!led_pdata) {
@@ -273,24 +279,18 @@  static int mlxreg_led_probe(struct platform_device *pdev)
 	priv->pdev = pdev;
 	priv->pdata = led_pdata;
 
+	ret = devm_add_action_or_reset(&pdev->dev, mlxreg_led_mutex_destroy,
+				       &priv->access_lock);
+	if (ret)
+		return ret;
 	return mlxreg_led_config(priv);
 }
 
-static int mlxreg_led_remove(struct platform_device *pdev)
-{
-	struct mlxreg_led_priv_data *priv = dev_get_drvdata(&pdev->dev);
-
-	mutex_destroy(&priv->access_lock);
-
-	return 0;
-}
-
 static struct platform_driver mlxreg_led_driver = {
 	.driver = {
 	    .name = "leds-mlxreg",
 	},
 	.probe = mlxreg_led_probe,
-	.remove = mlxreg_led_remove,
 };
 
 module_platform_driver(mlxreg_led_driver);