summaryrefslogtreecommitdiff
path: root/drivers/power
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2015-02-24 15:33:50 +1100
committerSebastian Reichel <sre@kernel.org>2015-02-26 01:50:22 +0100
commit5d8a4219a0795a321606c51582898223db80e874 (patch)
tree138911df8103697cc44bee53e75650684ece1964 /drivers/power
parent881f985a256839de2bb220dea5a4c59b8fa99b82 (diff)
power_supply core: support use of devres to register/unregister a power supply.
Using devm_power_supply_register allows the unregister to happen automatically on error or final put. Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Sebastian Reichel <sre@kernel.org>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/power_supply_core.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index 694e8cddd5c1..44c810456212 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -617,6 +617,51 @@ int power_supply_register_no_ws(struct device *parent, struct power_supply *psy)
}
EXPORT_SYMBOL_GPL(power_supply_register_no_ws);
+static void devm_power_supply_release(struct device *dev, void *res)
+{
+ struct power_supply **psy = res;
+
+ power_supply_unregister(*psy);
+}
+
+int devm_power_supply_register(struct device *parent, struct power_supply *psy)
+{
+ struct power_supply **ptr = devres_alloc(devm_power_supply_release,
+ sizeof(*ptr), GFP_KERNEL);
+ int ret;
+
+ if (!ptr)
+ return -ENOMEM;
+ ret = __power_supply_register(parent, psy, true);
+ if (ret < 0)
+ devres_free(ptr);
+ else {
+ *ptr = psy;
+ devres_add(parent, ptr);
+ }
+ return ret;
+}
+EXPORT_SYMBOL_GPL(devm_power_supply_register);
+
+int devm_power_supply_register_no_ws(struct device *parent, struct power_supply *psy)
+{
+ struct power_supply **ptr = devres_alloc(devm_power_supply_release,
+ sizeof(*ptr), GFP_KERNEL);
+ int ret;
+
+ if (!ptr)
+ return -ENOMEM;
+ ret = __power_supply_register(parent, psy, false);
+ if (ret < 0)
+ devres_free(ptr);
+ else {
+ *ptr = psy;
+ devres_add(parent, ptr);
+ }
+ return ret;
+}
+EXPORT_SYMBOL_GPL(devm_power_supply_register_no_ws);
+
void power_supply_unregister(struct power_supply *psy)
{
cancel_work_sync(&psy->changed_work);