diff mbox series

[10/13] leds: powernv: Fix devm vs. non-devm ordering

Message ID 1667983694-15040-11-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: 84ad6e5cd3e8 ("leds/powernv: Add driver for PowerNV platform")
Signed-off-by: Wang Yufen <wangyufen@huawei.com>
Cc: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
---
 drivers/leds/leds-powernv.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/leds/leds-powernv.c b/drivers/leds/leds-powernv.c
index 743e2cd..535f295 100644
--- a/drivers/leds/leds-powernv.c
+++ b/drivers/leds/leds-powernv.c
@@ -275,6 +275,11 @@  static int powernv_led_classdev(struct platform_device *pdev,
 	return rc;
 }
 
+static void powernv_led_mutex_destroy(void *lock)
+{
+	mutex_destroy(lock);
+}
+
 /* Platform driver probe */
 static int powernv_led_probe(struct platform_device *pdev)
 {
@@ -298,6 +303,10 @@  static int powernv_led_probe(struct platform_device *pdev)
 	}
 
 	mutex_init(&powernv_led_common->lock);
+	ret = devm_add_action_or_reset(dev, powernv_led_mutex_destroy,
+				       &powernv_led_common->lock);
+	if (ret)
+		return ret;
 	powernv_led_common->max_led_type = cpu_to_be64(OPAL_SLOT_LED_TYPE_MAX);
 
 	platform_set_drvdata(pdev, powernv_led_common);
@@ -317,9 +326,6 @@  static int powernv_led_remove(struct platform_device *pdev)
 	powernv_led_common = platform_get_drvdata(pdev);
 	powernv_led_common->led_disabled = true;
 
-	/* Destroy lock */
-	mutex_destroy(&powernv_led_common->lock);
-
 	dev_info(&pdev->dev, "PowerNV led module unregistered\n");
 	return 0;
 }