[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1667983694-15040-4-git-send-email-wangyufen@huawei.com>
Date: Wed, 9 Nov 2022 16:48:04 +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 03/13] leds: lm3532: 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: bc1b8492c764 ("leds: lm3532: Introduce the lm3532 LED driver")
Signed-off-by: Wang Yufen <wangyufen@...wei.com>
Cc: Dan Murphy <dmurphy@...com>
---
drivers/leds/leds-lm3532.c | 10 ++++++++++
1 file changed, 10 insertions(+)
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);
--
1.8.3.1
Powered by blists - more mailing lists