Skip to content

Commit 2681bba

Browse files
t-8chTzung-Bi Shih
authored andcommitted
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]>
1 parent 5b8feca commit 2681bba

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

drivers/acpi/battery.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,21 @@ void battery_hook_register(struct acpi_battery_hook *hook)
756756
}
757757
EXPORT_SYMBOL_GPL(battery_hook_register);
758758

759+
static void devm_battery_hook_unregister(void *data)
760+
{
761+
struct acpi_battery_hook *hook = data;
762+
763+
battery_hook_unregister(hook);
764+
}
765+
766+
int devm_battery_hook_register(struct device *dev, struct acpi_battery_hook *hook)
767+
{
768+
battery_hook_register(hook);
769+
770+
return devm_add_action_or_reset(dev, devm_battery_hook_unregister, hook);
771+
}
772+
EXPORT_SYMBOL_GPL(devm_battery_hook_register);
773+
759774
/*
760775
* This function gets called right after the battery sysfs
761776
* attributes have been added, so that the drivers that

include/acpi/battery.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef __ACPI_BATTERY_H
33
#define __ACPI_BATTERY_H
44

5+
#include <linux/device.h>
56
#include <linux/power_supply.h>
67

78
#define ACPI_BATTERY_CLASS "battery"
@@ -19,5 +20,6 @@ struct acpi_battery_hook {
1920

2021
void battery_hook_register(struct acpi_battery_hook *hook);
2122
void battery_hook_unregister(struct acpi_battery_hook *hook);
23+
int devm_battery_hook_register(struct device *dev, struct acpi_battery_hook *hook);
2224

2325
#endif

0 commit comments

Comments
 (0)