Re:[PATCH v6] ACPI: battery: prevent sysfs_add_battery re-entry on rapid events

From: GuangFei Luo

Date: Tue Sep 23 2025 - 12:19:13 EST


Yes, in my tests with battery hot-plug, I observed that
acpi_battery_notify() can be triggered multiple times in quick
succession. Only adding a lock inside acpi_battery_notify()
is sufficient.

The functions battery_hook_add_battery(), battery_hook_remove_battery(),
and sysfs_remove_battery() already acquire locks, so their internal
accesses are safe.

acpi_battery_refresh() does check battery->bat, but its child
functions (sysfs_add_battery() and sysfs_remove_battery()) already
handle locking.

In acpi_battery_notify(), battery->bat has no lock. However, the
check of battery->bat is at the very end of the function. During
earlier calls, battery->bat has already been protected by locks, so
re-entry will not cause issues.