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-10-git-send-email-wangyufen@huawei.com>
Date:   Wed, 9 Nov 2022 16:48:10 +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>,
        Sean Wang <sean.wang@...iatek.com>
Subject: [PATCH 09/13] leds: mt6323: 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: 216ec6cc4c19 ("leds: Add LED support for MT6323 PMIC")
Signed-off-by: Wang Yufen <wangyufen@...wei.com>
Cc: Sean Wang <sean.wang@...iatek.com>
---
 drivers/leds/leds-mt6323.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/leds-mt6323.c b/drivers/leds/leds-mt6323.c
index f59e0e8..2dacaca 100644
--- a/drivers/leds/leds-mt6323.c
+++ b/drivers/leds/leds-mt6323.c
@@ -361,6 +361,11 @@ static int mt6323_led_set_dt_default(struct led_classdev *cdev,
 	return ret;
 }
 
+static void mt6323_led_mutex_destroy(void *lock)
+{
+	mutex_destroy(lock);
+}
+
 static int mt6323_led_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -386,6 +391,10 @@ static int mt6323_led_probe(struct platform_device *pdev)
 	 */
 	leds->hw = hw;
 	mutex_init(&leds->lock);
+	ret = devm_add_action_or_reset(dev, mt6323_led_mutex_destroy,
+				       &leds->lock);
+	if (ret)
+		return ret;
 
 	status = MT6323_RG_DRV_32K_CK_PDN;
 	ret = regmap_update_bits(leds->hw->regmap, MT6323_TOP_CKPDN0,
@@ -464,8 +473,6 @@ static int mt6323_led_remove(struct platform_device *pdev)
 			   MT6323_RG_DRV_32K_CK_PDN_MASK,
 			   MT6323_RG_DRV_32K_CK_PDN);
 
-	mutex_destroy(&leds->lock);
-
 	return 0;
 }
 
-- 
1.8.3.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ