On Sat, Sep 13, 2025 at 12:25:16AM +0800, GuangFei Luo wrote: > Hi Greg, > > Thanks for your review and suggestion. > > I've updated sysfs_add_battery() to address your comment. > The locking is now applied explicitly inside the function > to prevent re-entry issues, while keeping the function > self-contained for all call sites. > > Patch version: v3 > > Thanks, > GuangFei > > 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@xxxxxxxxx/ > > 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: Note, none of the above should be here in the changelog body, it should be below the --- line. > diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c > index 6905b56bf3e4..f6d4a8b39a9c 100644 > --- a/drivers/acpi/battery.c > +++ b/drivers/acpi/battery.c > @@ -850,6 +850,12 @@ static void __exit battery_hook_exit(void) > > static int sysfs_add_battery(struct acpi_battery *battery) > { > + mutex_lock(&battery->sysfs_lock); Again, can you use guard() to make this logic simpler? That would turn this into a much smaller patch. thanks, greg k-h