aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/core.c
diff options
context:
space:
mode:
authorJeffrey Carlyle <jeff.carlyle@motorola.com>2010-10-08 15:49:19 -0400
committerLiam Girdwood <lrg@slimlogic.co.uk>2010-10-28 17:40:31 -0400
commit8cbf811dfd027bde8504e541d0009c5722b98be5 (patch)
tree0f7190a0c3680485ad7893a36d37967ae8f3c526 /drivers/regulator/core.c
parent688fe99a439f7c9dfcc52fbf7cb347f140a2dc8b (diff)
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>
Diffstat (limited to 'drivers/regulator/core.c')
-rw-r--r--drivers/regulator/core.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 4fa08c85f3ce..f1d10c974cd4 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -64,7 +64,8 @@ struct regulator {
64}; 64};
65 65
66static int _regulator_is_enabled(struct regulator_dev *rdev); 66static int _regulator_is_enabled(struct regulator_dev *rdev);
67static int _regulator_disable(struct regulator_dev *rdev); 67static int _regulator_disable(struct regulator_dev *rdev,
68 struct regulator_dev **supply_rdev_ptr);
68static int _regulator_get_voltage(struct regulator_dev *rdev); 69static int _regulator_get_voltage(struct regulator_dev *rdev);
69static int _regulator_get_current_limit(struct regulator_dev *rdev); 70static int _regulator_get_current_limit(struct regulator_dev *rdev);
70static unsigned int _regulator_get_mode(struct regulator_dev *rdev); 71static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
@@ -1354,7 +1355,8 @@ int regulator_enable(struct regulator *regulator)
1354EXPORT_SYMBOL_GPL(regulator_enable); 1355EXPORT_SYMBOL_GPL(regulator_enable);
1355 1356
1356/* locks held by regulator_disable() */ 1357/* locks held by regulator_disable() */
1357static int _regulator_disable(struct regulator_dev *rdev) 1358static int _regulator_disable(struct regulator_dev *rdev,
1359 struct regulator_dev **supply_rdev_ptr)
1358{ 1360{
1359 int ret = 0; 1361 int ret = 0;
1360 1362
@@ -1382,8 +1384,7 @@ static int _regulator_disable(struct regulator_dev *rdev)
1382 } 1384 }
1383 1385
1384 /* decrease our supplies ref count and disable if required */ 1386 /* decrease our supplies ref count and disable if required */
1385 if (rdev->supply) 1387 *supply_rdev_ptr = rdev->supply;
1386 _regulator_disable(rdev->supply);
1387 1388
1388 rdev->use_count = 0; 1389 rdev->use_count = 0;
1389 } else if (rdev->use_count > 1) { 1390 } else if (rdev->use_count > 1) {
@@ -1413,17 +1414,29 @@ static int _regulator_disable(struct regulator_dev *rdev)
1413int regulator_disable(struct regulator *regulator) 1414int regulator_disable(struct regulator *regulator)
1414{ 1415{
1415 struct regulator_dev *rdev = regulator->rdev; 1416 struct regulator_dev *rdev = regulator->rdev;
1417 struct regulator_dev *supply_rdev = NULL;
1416 int ret = 0; 1418 int ret = 0;
1417 1419
1418 mutex_lock(&rdev->mutex); 1420 mutex_lock(&rdev->mutex);
1419 ret = _regulator_disable(rdev); 1421 ret = _regulator_disable(rdev, &supply_rdev);
1420 mutex_unlock(&rdev->mutex); 1422 mutex_unlock(&rdev->mutex);
1423
1424 /* decrease our supplies ref count and disable if required */
1425 while (supply_rdev != NULL) {
1426 rdev = supply_rdev;
1427
1428 mutex_lock(&rdev->mutex);
1429 _regulator_disable(rdev, &supply_rdev);
1430 mutex_unlock(&rdev->mutex);
1431 }
1432
1421 return ret; 1433 return ret;
1422} 1434}
1423EXPORT_SYMBOL_GPL(regulator_disable); 1435EXPORT_SYMBOL_GPL(regulator_disable);
1424 1436
1425/* locks held by regulator_force_disable() */ 1437/* locks held by regulator_force_disable() */
1426static int _regulator_force_disable(struct regulator_dev *rdev) 1438static int _regulator_force_disable(struct regulator_dev *rdev,
1439 struct regulator_dev **supply_rdev_ptr)
1427{ 1440{
1428 int ret = 0; 1441 int ret = 0;
1429 1442
@@ -1442,8 +1455,7 @@ static int _regulator_force_disable(struct regulator_dev *rdev)
1442 } 1455 }
1443 1456
1444 /* decrease our supplies ref count and disable if required */ 1457 /* decrease our supplies ref count and disable if required */
1445 if (rdev->supply) 1458 *supply_rdev_ptr = rdev->supply;
1446 _regulator_disable(rdev->supply);
1447 1459
1448 rdev->use_count = 0; 1460 rdev->use_count = 0;
1449 return ret; 1461 return ret;
@@ -1460,12 +1472,17 @@ static int _regulator_force_disable(struct regulator_dev *rdev)
1460 */ 1472 */
1461int regulator_force_disable(struct regulator *regulator) 1473int regulator_force_disable(struct regulator *regulator)
1462{ 1474{
1475 struct regulator_dev *supply_rdev = NULL;
1463 int ret; 1476 int ret;
1464 1477
1465 mutex_lock(&regulator->rdev->mutex); 1478 mutex_lock(&regulator->rdev->mutex);
1466 regulator->uA_load = 0; 1479 regulator->uA_load = 0;
1467 ret = _regulator_force_disable(regulator->rdev); 1480 ret = _regulator_force_disable(regulator->rdev, &supply_rdev);
1468 mutex_unlock(&regulator->rdev->mutex); 1481 mutex_unlock(&regulator->rdev->mutex);
1482
1483 if (supply_rdev)
1484 regulator_disable(get_device_regulator(rdev_get_dev(supply_rdev)));
1485
1469 return ret; 1486 return ret;
1470} 1487}
1471EXPORT_SYMBOL_GPL(regulator_force_disable); 1488EXPORT_SYMBOL_GPL(regulator_force_disable);