[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1667983694-15040-7-git-send-email-wangyufen@huawei.com>
Date: Wed, 9 Nov 2022 16:48:07 +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 06/13] leds: lp50xx: 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: 242b81170fb8 ("leds: lp50xx: Add the LP50XX family of the RGB LED driver")
Signed-off-by: Wang Yufen <wangyufen@...wei.com>
Cc: Dan Murphy <dmurphy@...com>
---
drivers/leds/leds-lp50xx.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c
index 28d6b39..fcec568e 100644
--- a/drivers/leds/leds-lp50xx.c
+++ b/drivers/leds/leds-lp50xx.c
@@ -521,6 +521,11 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
return ret;
}
+static void lp50xx_mutex_destroy(void *lock)
+{
+ mutex_destroy(lock);
+}
+
static int lp50xx_probe(struct i2c_client *client)
{
struct lp50xx *led;
@@ -539,6 +544,11 @@ static int lp50xx_probe(struct i2c_client *client)
return -ENOMEM;
mutex_init(&led->lock);
+ ret = devm_add_action_or_reset(&client->dev, lp50xx_mutex_destroy,
+ &led->lock);
+ if (ret)
+ return ret;
+
led->client = client;
led->dev = &client->dev;
led->chip_info = device_get_match_data(&client->dev);
@@ -577,8 +587,6 @@ static void lp50xx_remove(struct i2c_client *client)
if (ret)
dev_err(led->dev, "Failed to disable regulator\n");
}
-
- mutex_destroy(&led->lock);
}
static const struct i2c_device_id lp50xx_id[] = {
--
1.8.3.1
Powered by blists - more mailing lists