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-5-git-send-email-wangyufen@huawei.com>
Date:   Wed, 9 Nov 2022 16:48:05 +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>,
        Dan Murphy <dmurphy@...com>
Subject: [PATCH 04/13] leds: lm3692x: 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: 9699cb6bbef2 ("leds: lm3692x: Introduce LM3692x dual string driver")
Signed-off-by: Wang Yufen <wangyufen@...wei.com>
Cc: Dan Murphy <dmurphy@...com>
---
 drivers/leds/leds-lm3692x.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/leds-lm3692x.c b/drivers/leds/leds-lm3692x.c
index 54b4662..aa1b0cc 100644
--- a/drivers/leds/leds-lm3692x.c
+++ b/drivers/leds/leds-lm3692x.c
@@ -456,6 +456,11 @@ static int lm3692x_probe_dt(struct lm3692x_led *led)
 	return ret;
 }
 
+static void lm3692x_mutex_destroy(void *lock)
+{
+	mutex_destroy(lock);
+}
+
 static int lm3692x_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
@@ -472,6 +477,11 @@ static int lm3692x_probe(struct i2c_client *client,
 	led->model_id = id->driver_data;
 	i2c_set_clientdata(client, led);
 
+	ret = devm_add_action_or_reset(&client->dev, lm3692x_mutex_destroy,
+				       &led->lock);
+	if (ret)
+		return ret;
+
 	led->regmap = devm_regmap_init_i2c(client, &lm3692x_regmap_config);
 	if (IS_ERR(led->regmap)) {
 		ret = PTR_ERR(led->regmap);
@@ -496,7 +506,6 @@ static void lm3692x_remove(struct i2c_client *client)
 	struct lm3692x_led *led = i2c_get_clientdata(client);
 
 	lm3692x_leds_disable(led);
-	mutex_destroy(&led->lock);
 }
 
 static const struct i2c_device_id lm3692x_id[] = {
-- 
1.8.3.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ