[PATCH 01/13] leds: cr0014114: Fix devm vs. non-devm ordering

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: 9e50d5fb0d18 ("leds: add LED driver for CR0014114 board")
Signed-off-by: Wang Yufen <wangyufen@xxxxxxxxxx>
Cc: Oleh Kravchenko <oleg@xxxxxxxxxx>
---
 drivers/leds/leds-cr0014114.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/leds-cr0014114.c b/drivers/leds/leds-cr0014114.c
index c87686b..f3a0320 100644
--- a/drivers/leds/leds-cr0014114.c
+++ b/drivers/leds/leds-cr0014114.c
@@ -211,6 +211,11 @@ static int cr0014114_probe_dt(struct cr0014114 *priv)
 	return 0;
 }
 
+static void cr0014114_mutex_destroy(void *lock)
+{
+	mutex_destroy(lock);
+}
+
 static int cr0014114_probe(struct spi_device *spi)
 {
 	struct cr0014114	*priv;
@@ -240,6 +245,11 @@ static int cr0014114_probe(struct spi_device *spi)
 	priv->delay	= jiffies -
 			  msecs_to_jiffies(CR_FW_DELAY_MSEC);
 
+	ret = devm_add_action_or_reset(&spi->dev, cr0014114_mutex_destroy,
+				       &priv->lock);
+	if (ret)
+		return ret;
+
 	priv->do_recount = true;
 	ret = cr0014114_sync(priv);
 	if (ret) {
@@ -271,7 +281,6 @@ static void cr0014114_remove(struct spi_device *spi)
 	struct cr0014114 *priv = spi_get_drvdata(spi);
 
 	cancel_delayed_work_sync(&priv->work);
-	mutex_destroy(&priv->lock);
 }
 
 static const struct of_device_id cr0014114_dt_ids[] = {
-- 
1.8.3.1




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux