diff mbox series

[03/13] leds: lm3532: Fix devm vs. non-devm ordering

Message ID 1667983694-15040-4-git-send-email-wangyufen@huawei.com
State New
Headers show
Series leds: Fix devm vs. non-devm ordering | expand

Commit Message

wangyufen Nov. 9, 2022, 8:48 a.m. UTC
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: bc1b8492c764 ("leds: lm3532: Introduce the lm3532 LED driver")
Signed-off-by: Wang Yufen <wangyufen@huawei.com>
Cc: Dan Murphy <dmurphy@ti.com>
---
 drivers/leds/leds-lm3532.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c
index db64d44..a052966 100644
--- a/drivers/leds/leds-lm3532.c
+++ b/drivers/leds/leds-lm3532.c
@@ -663,6 +663,11 @@  static int lm3532_parse_node(struct lm3532_data *priv)
 	return ret;
 }
 
+static void lm3532_mutex_destroy(void *lock)
+{
+	mutex_destroy(lock);
+}
+
 static int lm3532_probe(struct i2c_client *client,
 			   const struct i2c_device_id *id)
 {
@@ -693,6 +698,11 @@  static int lm3532_probe(struct i2c_client *client,
 	}
 
 	mutex_init(&drvdata->lock);
+	ret = devm_add_action_or_reset(&client->dev, lm3532_mutex_destroy,
+				       &drvdata->lock);
+	if (ret)
+		return ret;
+
 	i2c_set_clientdata(client, drvdata);
 
 	ret = lm3532_parse_node(drvdata);