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]
Date:   Wed, 9 Nov 2022 16:48:14 +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>,
        Linus Walleij <linus.walleij@...aro.org>
Subject: [PATCH 13/13] leds: rt8515: 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: e1c6edcbea13 ("leds: rt8515: Add Richtek RT8515 LED driver")
Signed-off-by: Wang Yufen <wangyufen@...wei.com>
Cc: Linus Walleij <linus.walleij@...aro.org>
---
 drivers/leds/flash/leds-rt8515.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/flash/leds-rt8515.c b/drivers/leds/flash/leds-rt8515.c
index 44904fde..f2d92ea 100644
--- a/drivers/leds/flash/leds-rt8515.c
+++ b/drivers/leds/flash/leds-rt8515.c
@@ -273,6 +273,11 @@ static void rt8515_determine_max_intensity(struct rt8515 *rt,
 	*max_intensity_setting = max_intensity;
 }
 
+static void rt8515_mutex_destroy(void *lock)
+{
+	mutex_destroy(lock);
+}
+
 static int rt8515_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -338,13 +343,16 @@ static int rt8515_probe(struct platform_device *pdev)
 	led->flags |= LED_CORE_SUSPENDRESUME | LED_DEV_CAP_FLASH;
 
 	mutex_init(&rt->lock);
+	ret = devm_add_action_or_reset(dev, rt8515_mutex_destroy,
+				       &rt->lock);
+	if (ret)
+		return ret;
 
 	platform_set_drvdata(pdev, rt);
 
 	ret = devm_led_classdev_flash_register_ext(dev, fled, &init_data);
 	if (ret) {
 		fwnode_handle_put(child);
-		mutex_destroy(&rt->lock);
 		dev_err(dev, "can't register LED %s\n", led->name);
 		return ret;
 	}
@@ -373,7 +381,6 @@ static int rt8515_remove(struct platform_device *pdev)
 
 	rt8515_v4l2_flash_release(rt);
 	del_timer_sync(&rt->powerdown_timer);
-	mutex_destroy(&rt->lock);
 
 	return 0;
 }
-- 
1.8.3.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ