diff options
author | Thomas Weißschuh <[email protected]> | 2024-06-30 22:54:08 +0200 |
---|---|---|
committer | Tzung-Bi Shih <[email protected]> | 2024-07-01 21:22:18 +0800 |
commit | 2681bbaa39cc2b5711494cc7e0166538f24e9c16 (patch) | |
tree | e42841d1449d8caa3b847e457346cbc4d0981b75 | |
parent | 5b8feca8dee443055049c8ccfdd97f64a0e1d2b4 (diff) |
ACPI: battery: add devm_battery_hook_register()
Add a utility function for device-managed registration of battery hooks.
The function makes it easier to manage the lifecycle of a hook.
Acked-by: Rafael J. Wysocki <[email protected]>
Signed-off-by: Thomas Weißschuh <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Tzung-Bi Shih <[email protected]>
-rw-r--r-- | drivers/acpi/battery.c | 15 | ||||
-rw-r--r-- | include/acpi/battery.h | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index b379401ff1c2..6ea979f76f84 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -756,6 +756,21 @@ end: } EXPORT_SYMBOL_GPL(battery_hook_register); +static void devm_battery_hook_unregister(void *data) +{ + struct acpi_battery_hook *hook = data; + + battery_hook_unregister(hook); +} + +int devm_battery_hook_register(struct device *dev, struct acpi_battery_hook *hook) +{ + battery_hook_register(hook); + + return devm_add_action_or_reset(dev, devm_battery_hook_unregister, hook); +} +EXPORT_SYMBOL_GPL(devm_battery_hook_register); + /* * This function gets called right after the battery sysfs * attributes have been added, so that the drivers that diff --git a/include/acpi/battery.h b/include/acpi/battery.h index 611a2561a014..c93f16dfb944 100644 --- a/include/acpi/battery.h +++ b/include/acpi/battery.h @@ -2,6 +2,7 @@ #ifndef __ACPI_BATTERY_H #define __ACPI_BATTERY_H +#include <linux/device.h> #include <linux/power_supply.h> #define ACPI_BATTERY_CLASS "battery" @@ -19,5 +20,6 @@ struct acpi_battery_hook { void battery_hook_register(struct acpi_battery_hook *hook); void battery_hook_unregister(struct acpi_battery_hook *hook); +int devm_battery_hook_register(struct device *dev, struct acpi_battery_hook *hook); #endif |