lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1667983694-15040-11-git-send-email-wangyufen@huawei.com>
Date:   Wed, 9 Nov 2022 16:48:11 +0800
From:   Wang Yufen <wangyufen@...wei.com>
To:     <linux-leds@...r.kernel.org>, <linux-kernel@...r.kernel.org>
CC:     <pavel@....cz>, Wang Yufen <wangyufen@...wei.com>,
        Vasant Hegde <hegdevasant@...ux.vnet.ibm.com>
Subject: [PATCH 10/13] leds: powernv: Fix devm vs. non-devm ordering

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@...wei.com>
Cc: Vasant Hegde <hegdevasant@...ux.vnet.ibm.com>
---
 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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ