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-13-git-send-email-wangyufen@huawei.com>
Date:   Wed, 9 Nov 2022 16:48:13 +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>,
        Christian Mauderer <oss@...auderer.de>
Subject: [PATCH 12/13] leds: spi-byte: 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: e9a804d7a428 ("leds: spi-byte: add single byte SPI LED driver")
Signed-off-by: Wang Yufen <wangyufen@...wei.com>
Cc: Christian Mauderer <oss@...auderer.de>
---
 drivers/leds/leds-spi-byte.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/leds/leds-spi-byte.c b/drivers/leds/leds-spi-byte.c
index 2bc5c99..a169780 100644
--- a/drivers/leds/leds-spi-byte.c
+++ b/drivers/leds/leds-spi-byte.c
@@ -78,6 +78,11 @@ static int spi_byte_brightness_set_blocking(struct led_classdev *dev,
 	return ret;
 }
 
+static void spi_byte_mutex_destroy(void *lock)
+{
+	mutex_destroy(lock);
+}
+
 static int spi_byte_probe(struct spi_device *spi)
 {
 	struct device_node *child;
@@ -101,6 +106,10 @@ static int spi_byte_probe(struct spi_device *spi)
 	strlcpy(led->name, name, sizeof(led->name));
 	led->spi = spi;
 	mutex_init(&led->mutex);
+	ret = devm_add_action_or_reset(dev, spi_byte_mutex_destroy,
+				       &led->mutex);
+	if (ret)
+		return ret;
 	led->cdef = device_get_match_data(dev);
 	led->ldev.name = led->name;
 	led->ldev.brightness = LED_OFF;
@@ -121,25 +130,15 @@ static int spi_byte_probe(struct spi_device *spi)
 					 led->ldev.brightness);
 
 	ret = devm_led_classdev_register(&spi->dev, &led->ldev);
-	if (ret) {
-		mutex_destroy(&led->mutex);
+	if (ret)
 		return ret;
-	}
 	spi_set_drvdata(spi, led);
 
 	return 0;
 }
 
-static void spi_byte_remove(struct spi_device *spi)
-{
-	struct spi_byte_led	*led = spi_get_drvdata(spi);
-
-	mutex_destroy(&led->mutex);
-}
-
 static struct spi_driver spi_byte_driver = {
 	.probe		= spi_byte_probe,
-	.remove		= spi_byte_remove,
 	.driver = {
 		.name		= KBUILD_MODNAME,
 		.of_match_table	= spi_byte_dt_ids,
-- 
1.8.3.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ