diff options
author | Hans de Goede <hdegoede@redhat.com> | 2015-06-09 17:37:56 -0400 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2015-06-10 10:15:54 -0400 |
commit | fe27e1dfe9962b07215ee01445926306ddbb7c25 (patch) | |
tree | b0e05cfc8302404ba84e0b4c3d270ff4b4d1b762 | |
parent | a6e6b63ee2798f18e0e786feb407cc7846077ea3 (diff) |
power: Add devm_power_supply_get_by_phandle() helper function
This commit adds a resource-managed version of the
power_supply_get_by_phandle() function.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
-rw-r--r-- | drivers/power/power_supply_core.c | 39 | ||||
-rw-r--r-- | include/linux/power_supply.h | 5 |
2 files changed, 44 insertions, 0 deletions
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c index 4bc0c7f459a5..a44d4554af4f 100644 --- a/drivers/power/power_supply_core.c +++ b/drivers/power/power_supply_core.c | |||
@@ -446,6 +446,45 @@ struct power_supply *power_supply_get_by_phandle(struct device_node *np, | |||
446 | return psy; | 446 | return psy; |
447 | } | 447 | } |
448 | EXPORT_SYMBOL_GPL(power_supply_get_by_phandle); | 448 | EXPORT_SYMBOL_GPL(power_supply_get_by_phandle); |
449 | |||
450 | static void devm_power_supply_put(struct device *dev, void *res) | ||
451 | { | ||
452 | struct power_supply **psy = res; | ||
453 | |||
454 | power_supply_put(*psy); | ||
455 | } | ||
456 | |||
457 | /** | ||
458 | * devm_power_supply_get_by_phandle() - Resource managed version of | ||
459 | * power_supply_get_by_phandle() | ||
460 | * @dev: Pointer to device holding phandle property | ||
461 | * @phandle_name: Name of property holding a power supply phandle | ||
462 | * | ||
463 | * Return: On success returns a reference to a power supply with | ||
464 | * matching name equals to value under @property, NULL or ERR_PTR otherwise. | ||
465 | */ | ||
466 | struct power_supply *devm_power_supply_get_by_phandle(struct device *dev, | ||
467 | const char *property) | ||
468 | { | ||
469 | struct power_supply **ptr, *psy; | ||
470 | |||
471 | if (!dev->of_node) | ||
472 | return ERR_PTR(-ENODEV); | ||
473 | |||
474 | ptr = devres_alloc(devm_power_supply_put, sizeof(*ptr), GFP_KERNEL); | ||
475 | if (!ptr) | ||
476 | return ERR_PTR(-ENOMEM); | ||
477 | |||
478 | psy = power_supply_get_by_phandle(dev->of_node, property); | ||
479 | if (IS_ERR_OR_NULL(psy)) { | ||
480 | devres_free(ptr); | ||
481 | } else { | ||
482 | *ptr = psy; | ||
483 | devres_add(dev, ptr); | ||
484 | } | ||
485 | return psy; | ||
486 | } | ||
487 | EXPORT_SYMBOL_GPL(devm_power_supply_get_by_phandle); | ||
449 | #endif /* CONFIG_OF */ | 488 | #endif /* CONFIG_OF */ |
450 | 489 | ||
451 | int power_supply_get_property(struct power_supply *psy, | 490 | int power_supply_get_property(struct power_supply *psy, |
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 0395bcb18ddb..ef9f1592185d 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h | |||
@@ -292,10 +292,15 @@ extern void power_supply_put(struct power_supply *psy); | |||
292 | #ifdef CONFIG_OF | 292 | #ifdef CONFIG_OF |
293 | extern struct power_supply *power_supply_get_by_phandle(struct device_node *np, | 293 | extern struct power_supply *power_supply_get_by_phandle(struct device_node *np, |
294 | const char *property); | 294 | const char *property); |
295 | extern struct power_supply *devm_power_supply_get_by_phandle( | ||
296 | struct device *dev, const char *property); | ||
295 | #else /* !CONFIG_OF */ | 297 | #else /* !CONFIG_OF */ |
296 | static inline struct power_supply * | 298 | static inline struct power_supply * |
297 | power_supply_get_by_phandle(struct device_node *np, const char *property) | 299 | power_supply_get_by_phandle(struct device_node *np, const char *property) |
298 | { return NULL; } | 300 | { return NULL; } |
301 | static inline struct power_supply * | ||
302 | devm_power_supply_get_by_phandle(struct device *dev, const char *property) | ||
303 | { return NULL; } | ||
299 | #endif /* CONFIG_OF */ | 304 | #endif /* CONFIG_OF */ |
300 | extern void power_supply_changed(struct power_supply *psy); | 305 | extern void power_supply_changed(struct power_supply *psy); |
301 | extern int power_supply_am_i_supplied(struct power_supply *psy); | 306 | extern int power_supply_am_i_supplied(struct power_supply *psy); |