Revert "ACPI: battery: Simplify battery hook locking"

This reverts commit fee4fda569.
This commit is contained in:
Ksawlii 2024-11-24 00:23:00 +01:00
parent a7dca58100
commit 108e451c4b

View file

@ -695,27 +695,27 @@ static LIST_HEAD(acpi_battery_list);
static LIST_HEAD(battery_hook_list);
static DEFINE_MUTEX(hook_mutex);
static void battery_hook_unregister_unlocked(struct acpi_battery_hook *hook)
static void __battery_hook_unregister(struct acpi_battery_hook *hook, int lock)
{
struct acpi_battery *battery;
/*
* In order to remove a hook, we first need to
* de-register all the batteries that are registered.
*/
if (lock)
mutex_lock(&hook_mutex);
list_for_each_entry(battery, &acpi_battery_list, list) {
hook->remove_battery(battery->bat);
}
list_del(&hook->list);
if (lock)
mutex_unlock(&hook_mutex);
pr_info("extension unregistered: %s\n", hook->name);
}
void battery_hook_unregister(struct acpi_battery_hook *hook)
{
mutex_lock(&hook_mutex);
battery_hook_unregister_unlocked(hook);
mutex_unlock(&hook_mutex);
__battery_hook_unregister(hook, 1);
}
EXPORT_SYMBOL_GPL(battery_hook_unregister);
@ -741,7 +741,7 @@ void battery_hook_register(struct acpi_battery_hook *hook)
* hooks.
*/
pr_err("extension failed to load: %s", hook->name);
battery_hook_unregister_unlocked(hook);
__battery_hook_unregister(hook, 0);
goto end;
}
}
@ -778,7 +778,7 @@ static void battery_hook_add_battery(struct acpi_battery *battery)
*/
pr_err("error in extension, unloading: %s",
hook_node->name);
battery_hook_unregister_unlocked(hook_node);
__battery_hook_unregister(hook_node, 0);
}
}
mutex_unlock(&hook_mutex);
@ -811,7 +811,7 @@ static void __exit battery_hook_exit(void)
* need to remove the hooks.
*/
list_for_each_entry_safe(hook, ptr, &battery_hook_list, list) {
battery_hook_unregister(hook);
__battery_hook_unregister(hook, 1);
}
mutex_destroy(&hook_mutex);
}