diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-01-20 15:09:18 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-01-22 11:15:38 -0500 |
commit | d5ad34f7cb8b23ab165cabef69577a2a20d53195 (patch) | |
tree | e0eae78454ba62185c8732e256469bc186ae6438 /drivers/regulator | |
parent | 070b9079226d4f3e3e7c9f4eb81f2e02e7d99572 (diff) |
regulator: Implement devm_regulator_free()
Allow consumers to free regulators allocated using devm_regulator_get()
if they need to. This will not normally be required.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/core.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 214640db084b..88bcb111ca68 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -1421,6 +1421,34 @@ void regulator_put(struct regulator *regulator) | |||
1421 | } | 1421 | } |
1422 | EXPORT_SYMBOL_GPL(regulator_put); | 1422 | EXPORT_SYMBOL_GPL(regulator_put); |
1423 | 1423 | ||
1424 | static int devm_regulator_match(struct device *dev, void *res, void *data) | ||
1425 | { | ||
1426 | struct regulator **r = res; | ||
1427 | if (!r || !*r) { | ||
1428 | WARN_ON(!r || !*r); | ||
1429 | return 0; | ||
1430 | } | ||
1431 | return *r == data; | ||
1432 | } | ||
1433 | |||
1434 | /** | ||
1435 | * devm_regulator_put - Resource managed regulator_put() | ||
1436 | * @regulator: regulator to free | ||
1437 | * | ||
1438 | * Deallocate a regulator allocated with devm_regulator_get(). Normally | ||
1439 | * this function will not need to be called and the resource management | ||
1440 | * code will ensure that the resource is freed. | ||
1441 | */ | ||
1442 | void devm_regulator_put(struct regulator *regulator) | ||
1443 | { | ||
1444 | int rc; | ||
1445 | |||
1446 | rc = devres_destroy(regulator->dev, devm_regulator_release, | ||
1447 | devm_regulator_match, regulator); | ||
1448 | WARN_ON(rc); | ||
1449 | } | ||
1450 | EXPORT_SYMBOL_GPL(devm_regulator_put); | ||
1451 | |||
1424 | static int _regulator_can_change_status(struct regulator_dev *rdev) | 1452 | static int _regulator_can_change_status(struct regulator_dev *rdev) |
1425 | { | 1453 | { |
1426 | if (!rdev->constraints) | 1454 | if (!rdev->constraints) |