[PATCH] leds: lp5860: fix init error-path locking

kr494167@gmail.com posted 1 patch 4 days, 15 hours ago
There is a newer version of this series
drivers/leds/rgb/leds-lp5860-core.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH] leds: lp5860: fix init error-path locking
Posted by kr494167@gmail.com 4 days, 15 hours ago
From: surendra <kr494167@gmail.com>

lp5860_device_init() jumps to err_disable with the mutex held when
regmap_update_bits() fails. The error handler calls lp5860_chip_enable(),
which tries to acquire the same mutex and deadlocks.

Conversely, an lp5860_init_dt() failure reaches the same handler after the
mutex has been released, causing mutex_unlock() to operate on an unlocked
mutex.

Release the mutex immediately after the register update and keep the error
handler lockless.

Signed-off-by: surendra <kr494167@gmail.com>
---
 drivers/leds/rgb/leds-lp5860-core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/leds/rgb/leds-lp5860-core.c b/drivers/leds/rgb/leds-lp5860-core.c
index fd0e2f6e6e0f..e21d5f2302be 100644
--- a/drivers/leds/rgb/leds-lp5860-core.c
+++ b/drivers/leds/rgb/leds-lp5860-core.c
@@ -204,9 +204,9 @@ int lp5860_device_init(struct device *dev)
 	mutex_lock(&lp->lock);
 	ret = regmap_update_bits(lp->regmap, LP5860_REG_DEV_INITIAL, LP5860_MODE_MASK,
 				 LP5860_MODE_1 << LP5860_MODE_SHIFT);
+	mutex_unlock(&lp->lock);
 	if (ret)
 		goto err_disable;
-	mutex_unlock(&lp->lock);
 
 	ret = lp5860_init_dt(lp);
 	if (ret)
@@ -215,7 +215,6 @@ int lp5860_device_init(struct device *dev)
 	return 0;
 
 err_disable:
-	mutex_unlock(&lp->lock);
 	lp5860_chip_enable(lp, LP5860_CHIP_DISABLE);
 	return ret;
 }
-- 
2.55.0