Skip to content

Commit

Permalink
regulator: core: introduce function to lock regulators and its supplies
Browse files Browse the repository at this point in the history
Each regulator_dev is locked with its own mutex. This is fine as long
as only one regulator_dev is locked, but makes lockdep unhappy when we
have to walk up the supply chain like it can happen in
regulator_get_voltage:

regulator_get_voltage ->
 mutex_lock(&regulator->rdev->mutex) ->
_regulator_get_voltage(regulator->rdev) ->
regulator_get_voltage(rdev->supply) ->
mutex_lock(&regulator->rdev->mutex);

This causes lockdep to issue a possible deadlock warning.

There are at least two ways to work around this:

- We can always lock the whole supply chain using the functions
  introduced with this patch.
- We could store the current voltage in struct regulator_rdev so
  that we do not have to walk up the supply chain for the
  _regulator_get_voltage case.

Anyway, regulator_lock_supply/regulator_unlock_supply will be needed
once we allow regulator_set_voltage to optimize the supply voltages.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Sascha Hauer authored and Mark Brown committed Oct 1, 2015
1 parent 6ff33f3 commit 9f01cd4
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,45 @@ static bool have_full_constraints(void)
return has_full_constraints || of_have_populated_dt();
}

/**
* regulator_lock_supply - lock a regulator and its supplies
* @rdev: regulator source
*/
static void regulator_lock_supply(struct regulator_dev *rdev)
{
struct regulator *supply;
int i = 0;

while (1) {
mutex_lock_nested(&rdev->mutex, i++);
supply = rdev->supply;

if (!rdev->supply)
return;

rdev = supply->rdev;
}
}

/**
* regulator_unlock_supply - unlock a regulator and its supplies
* @rdev: regulator source
*/
static void regulator_unlock_supply(struct regulator_dev *rdev)
{
struct regulator *supply;

while (1) {
mutex_unlock(&rdev->mutex);
supply = rdev->supply;

if (!rdev->supply)
return;

rdev = supply->rdev;
}
}

/**
* of_get_regulator - get a regulator device node based on supply name
* @dev: Device pointer for the consumer (of regulator) device
Expand Down

0 comments on commit 9f01cd4

Please sign in to comment.