Skip to content

Commit 86309cb

Browse files
Wer-Wolfrafaeljw
authored andcommitted
ACPI: battery: Simplify battery hook locking
Move the conditional locking from __battery_hook_unregister() into battery_hook_unregister() and rename the low-level function to simplify the locking during battery hook removal. Reviewed-by: Ilpo Järvinen <[email protected]> Reviewed-by: Pali Rohár <[email protected]> Signed-off-by: Armin Wolf <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 9852d85 commit 86309cb

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

drivers/acpi/battery.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -703,28 +703,28 @@ static LIST_HEAD(acpi_battery_list);
703703
static LIST_HEAD(battery_hook_list);
704704
static DEFINE_MUTEX(hook_mutex);
705705

706-
static void __battery_hook_unregister(struct acpi_battery_hook *hook, int lock)
706+
static void battery_hook_unregister_unlocked(struct acpi_battery_hook *hook)
707707
{
708708
struct acpi_battery *battery;
709+
709710
/*
710711
* In order to remove a hook, we first need to
711712
* de-register all the batteries that are registered.
712713
*/
713-
if (lock)
714-
mutex_lock(&hook_mutex);
715714
list_for_each_entry(battery, &acpi_battery_list, list) {
716715
if (!hook->remove_battery(battery->bat, hook))
717716
power_supply_changed(battery->bat);
718717
}
719718
list_del(&hook->list);
720-
if (lock)
721-
mutex_unlock(&hook_mutex);
719+
722720
pr_info("extension unregistered: %s\n", hook->name);
723721
}
724722

725723
void battery_hook_unregister(struct acpi_battery_hook *hook)
726724
{
727-
__battery_hook_unregister(hook, 1);
725+
mutex_lock(&hook_mutex);
726+
battery_hook_unregister_unlocked(hook);
727+
mutex_unlock(&hook_mutex);
728728
}
729729
EXPORT_SYMBOL_GPL(battery_hook_unregister);
730730

@@ -750,7 +750,7 @@ void battery_hook_register(struct acpi_battery_hook *hook)
750750
* hooks.
751751
*/
752752
pr_err("extension failed to load: %s", hook->name);
753-
__battery_hook_unregister(hook, 0);
753+
battery_hook_unregister_unlocked(hook);
754754
goto end;
755755
}
756756

@@ -804,7 +804,7 @@ static void battery_hook_add_battery(struct acpi_battery *battery)
804804
*/
805805
pr_err("error in extension, unloading: %s",
806806
hook_node->name);
807-
__battery_hook_unregister(hook_node, 0);
807+
battery_hook_unregister_unlocked(hook_node);
808808
}
809809
}
810810
mutex_unlock(&hook_mutex);
@@ -837,7 +837,7 @@ static void __exit battery_hook_exit(void)
837837
* need to remove the hooks.
838838
*/
839839
list_for_each_entry_safe(hook, ptr, &battery_hook_list, list) {
840-
__battery_hook_unregister(hook, 1);
840+
battery_hook_unregister(hook);
841841
}
842842
mutex_destroy(&hook_mutex);
843843
}

0 commit comments

Comments
 (0)