[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1667983694-15040-8-git-send-email-wangyufen@huawei.com>
Date: Wed, 9 Nov 2022 16:48:08 +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 07/13] leds: lp8860: 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: a2169c9b762a ("leds: lp8860: Various fixes to align with LED framework")
Signed-off-by: Wang Yufen <wangyufen@...wei.com>
Cc: Dan Murphy <dmurphy@...com>
---
drivers/leds/leds-lp8860.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/leds/leds-lp8860.c b/drivers/leds/leds-lp8860.c
index e2b36d3..ca73d91 100644
--- a/drivers/leds/leds-lp8860.c
+++ b/drivers/leds/leds-lp8860.c
@@ -375,6 +375,11 @@ static int lp8860_init(struct lp8860_led *led)
.cache_type = REGCACHE_NONE,
};
+static void lp8860_mutex_destroy(void *lock)
+{
+ mutex_destroy(lock);
+}
+
static int lp8860_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -408,6 +413,10 @@ static int lp8860_probe(struct i2c_client *client,
led->led_dev.brightness_set_blocking = lp8860_brightness_set;
mutex_init(&led->lock);
+ ret = devm_add_action_or_reset(&client->dev, lp8860_mutex_destroy,
+ &led->lock);
+ if (ret)
+ return ret;
i2c_set_clientdata(client, led);
@@ -459,8 +468,6 @@ static void lp8860_remove(struct i2c_client *client)
dev_err(&led->client->dev,
"Failed to disable regulator\n");
}
-
- mutex_destroy(&led->lock);
}
static const struct i2c_device_id lp8860_id[] = {
--
1.8.3.1
Powered by blists - more mailing lists