Commit 5d8a4219 authored by NeilBrown's avatar NeilBrown Committed by Sebastian Reichel

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: default avatarNeilBrown <neilb@suse.de>
Signed-off-by: default avatarSebastian Reichel <sre@kernel.org>
parent 881f985a
...@@ -617,6 +617,51 @@ int power_supply_register_no_ws(struct device *parent, struct power_supply *psy) ...@@ -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); 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) void power_supply_unregister(struct power_supply *psy)
{ {
cancel_work_sync(&psy->changed_work); cancel_work_sync(&psy->changed_work);
......
...@@ -278,6 +278,10 @@ extern int power_supply_register(struct device *parent, ...@@ -278,6 +278,10 @@ extern int power_supply_register(struct device *parent,
struct power_supply *psy); struct power_supply *psy);
extern int power_supply_register_no_ws(struct device *parent, extern int power_supply_register_no_ws(struct device *parent,
struct power_supply *psy); struct power_supply *psy);
extern int devm_power_supply_register(struct device *parent,
struct power_supply *psy);
extern int devm_power_supply_register_no_ws(struct device *parent,
struct power_supply *psy);
extern void power_supply_unregister(struct power_supply *psy); extern void power_supply_unregister(struct power_supply *psy);
extern int power_supply_powers(struct power_supply *psy, struct device *dev); extern int power_supply_powers(struct power_supply *psy, struct device *dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment