]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
regulator: Implement devm_regulator_free()
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Fri, 20 Jan 2012 20:09:18 +0000 (20:09 +0000)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Sun, 22 Jan 2012 16:15:38 +0000 (16:15 +0000)
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>
drivers/regulator/core.c
include/linux/regulator/consumer.h

index 214640db084b466c931957d11f8eabd29dee9525..88bcb111ca6837e926c0fa9f60f9d652d0ce8100 100644 (file)
@@ -1421,6 +1421,34 @@ void regulator_put(struct regulator *regulator)
 }
 EXPORT_SYMBOL_GPL(regulator_put);
 
+static int devm_regulator_match(struct device *dev, void *res, void *data)
+{
+       struct regulator **r = res;
+       if (!r || !*r) {
+               WARN_ON(!r || !*r);
+               return 0;
+       }
+       return *r == data;
+}
+
+/**
+ * devm_regulator_put - Resource managed regulator_put()
+ * @regulator: regulator to free
+ *
+ * Deallocate a regulator allocated with devm_regulator_get(). Normally
+ * this function will not need to be called and the resource management
+ * code will ensure that the resource is freed.
+ */
+void devm_regulator_put(struct regulator *regulator)
+{
+       int rc;
+
+       rc = devres_destroy(regulator->dev, devm_regulator_release,
+                           devm_regulator_match, regulator);
+       WARN_ON(rc);
+}
+EXPORT_SYMBOL_GPL(devm_regulator_put);
+
 static int _regulator_can_change_status(struct regulator_dev *rdev)
 {
        if (!rdev->constraints)
index bcfe10658763dff7ed5ae791d51ac141333b411f..60c2f996d89576602c544c4cfa63d3f2996d25d0 100644 (file)
@@ -137,6 +137,7 @@ struct regulator *__must_check devm_regulator_get(struct device *dev,
 struct regulator *__must_check regulator_get_exclusive(struct device *dev,
                                                       const char *id);
 void regulator_put(struct regulator *regulator);
+void devm_regulator_free(struct regulator *regulator);
 
 /* regulator output control and status */
 int regulator_enable(struct regulator *regulator);