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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
Cc: Vasant Hegde <hegdevasant@xxxxxxxxxxxxxxxxxx>
---
 drivers/leds/leds-powernv.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

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;
 }
-- 
1.8.3.1




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux