On Fri, Sep 12, 2025 at 11:48:59PM +0800, GuangFei Luo wrote:
v3:
- Modified the earlier approach: since sysfs_add_battery() is invoked from multiple places, the most reliable way is to add the lock inside the function itself.
- sysfs_remove_battery() had a similar race issue in the past, which was fixed by adding a lock as well. Reference: https://lore.kernel.org/all/9c921c22a7f33397a6774d7fa076db9b6a0fd669
.1312318300.git.len.brown@intel.com/
v2:
- Fix missing mutex_unlock in acpi_battery_update() (Reported-by: kernel test robot)
v1: When removing and reinserting the laptop battery, ACPI can trigger two notifications in quick succession:
- ACPI_BATTERY_NOTIFY_STATUS (0x80)
- ACPI_BATTERY_NOTIFY_INFO (0x81)
Changelog should go below the --- line.
static int sysfs_add_battery(struct acpi_battery *battery) {
- mutex_lock(&battery->sysfs_lock);
Why not just use a guard() here? That would make the logic elsewhere much simpler.
thanks,
greg k-h