regulator: avoid deadlock when disabling regulator with supply
I have a regulator A that sets regulator B as its supply. When I call set_supply to add B as the supply for A, regulator A gets added to the supply_list for regulator B. When I call regulator_disable(A), I end up with a call chain like this: regulator_disable(A) > mutex_lock(A) > _regulator_disable(A) >> _regulator_disable(B) >>> _notifier_call_chain(B) >>>> mutex_lock(A) Which results in dead lock since we are trying to acquire the mutex lock for regulator A which we already hold. This patch addresses this issue by moving the call to disable regulator B outside of the lock aquired inside the initial call to regulator_disable. This change also addresses the issue of not acquiring the mutex for regulator B before calling _regulator_disable(B). Signed-off-by: Jeffrey Carlyle <jeff.carlyle@motorola.com> Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
This commit is contained in:
parent
688fe99a43
commit
8cbf811dfd
|
@ -64,7 +64,8 @@ struct regulator {
|
|||
};
|
||||
|
||||
static int _regulator_is_enabled(struct regulator_dev *rdev);
|
||||
static int _regulator_disable(struct regulator_dev *rdev);
|
||||
static int _regulator_disable(struct regulator_dev *rdev,
|
||||
struct regulator_dev **supply_rdev_ptr);
|
||||
static int _regulator_get_voltage(struct regulator_dev *rdev);
|
||||
static int _regulator_get_current_limit(struct regulator_dev *rdev);
|
||||
static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
|
||||
|
@ -1354,7 +1355,8 @@ int regulator_enable(struct regulator *regulator)
|
|||
EXPORT_SYMBOL_GPL(regulator_enable);
|
||||
|
||||
/* locks held by regulator_disable() */
|
||||
static int _regulator_disable(struct regulator_dev *rdev)
|
||||
static int _regulator_disable(struct regulator_dev *rdev,
|
||||
struct regulator_dev **supply_rdev_ptr)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
@ -1382,8 +1384,7 @@ static int _regulator_disable(struct regulator_dev *rdev)
|
|||
}
|
||||
|
||||
/* decrease our supplies ref count and disable if required */
|
||||
if (rdev->supply)
|
||||
_regulator_disable(rdev->supply);
|
||||
*supply_rdev_ptr = rdev->supply;
|
||||
|
||||
rdev->use_count = 0;
|
||||
} else if (rdev->use_count > 1) {
|
||||
|
@ -1413,17 +1414,29 @@ static int _regulator_disable(struct regulator_dev *rdev)
|
|||
int regulator_disable(struct regulator *regulator)
|
||||
{
|
||||
struct regulator_dev *rdev = regulator->rdev;
|
||||
struct regulator_dev *supply_rdev = NULL;
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&rdev->mutex);
|
||||
ret = _regulator_disable(rdev);
|
||||
ret = _regulator_disable(rdev, &supply_rdev);
|
||||
mutex_unlock(&rdev->mutex);
|
||||
|
||||
/* decrease our supplies ref count and disable if required */
|
||||
while (supply_rdev != NULL) {
|
||||
rdev = supply_rdev;
|
||||
|
||||
mutex_lock(&rdev->mutex);
|
||||
_regulator_disable(rdev, &supply_rdev);
|
||||
mutex_unlock(&rdev->mutex);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(regulator_disable);
|
||||
|
||||
/* locks held by regulator_force_disable() */
|
||||
static int _regulator_force_disable(struct regulator_dev *rdev)
|
||||
static int _regulator_force_disable(struct regulator_dev *rdev,
|
||||
struct regulator_dev **supply_rdev_ptr)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
@ -1442,8 +1455,7 @@ static int _regulator_force_disable(struct regulator_dev *rdev)
|
|||
}
|
||||
|
||||
/* decrease our supplies ref count and disable if required */
|
||||
if (rdev->supply)
|
||||
_regulator_disable(rdev->supply);
|
||||
*supply_rdev_ptr = rdev->supply;
|
||||
|
||||
rdev->use_count = 0;
|
||||
return ret;
|
||||
|
@ -1460,12 +1472,17 @@ static int _regulator_force_disable(struct regulator_dev *rdev)
|
|||
*/
|
||||
int regulator_force_disable(struct regulator *regulator)
|
||||
{
|
||||
struct regulator_dev *supply_rdev = NULL;
|
||||
int ret;
|
||||
|
||||
mutex_lock(®ulator->rdev->mutex);
|
||||
regulator->uA_load = 0;
|
||||
ret = _regulator_force_disable(regulator->rdev);
|
||||
ret = _regulator_force_disable(regulator->rdev, &supply_rdev);
|
||||
mutex_unlock(®ulator->rdev->mutex);
|
||||
|
||||
if (supply_rdev)
|
||||
regulator_disable(get_device_regulator(rdev_get_dev(supply_rdev)));
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(regulator_force_disable);
|
||||
|
|
Loading…
Reference in New Issue