From: Greg KH <gregkh@linuxfoundation.org>
To: GuangFei Luo <luogf2025@163.com>
Cc: rafael@kernel.org, dan.carpenter@linaro.org, lenb@kernel.org,
linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-pm@vger.kernel.org, lkp@intel.com, sre@kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v3] ACPI: battery: prevent sysfs_add_battery re-entry on rapid events
Date: Sat, 13 Sep 2025 08:05:13 +0200 [thread overview]
Message-ID: <2025091354-query-oblivion-9d18@gregkh> (raw)
In-Reply-To: <20250912162516.692861-1-luogf2025@163.com>
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@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:
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
next prev parent reply other threads:[~2025-09-13 6:05 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-10 14:26 [PATCH v2] ACPI: battery: prevent sysfs_add_battery re-entry on rapid events GuangFei Luo
2025-09-12 14:58 ` [PATCH v3] " GuangFei Luo
2025-09-12 15:48 ` GuangFei Luo
2025-09-12 15:57 ` Greg KH
2025-09-12 16:25 ` GuangFei Luo
2025-09-13 6:05 ` Greg KH [this message]
2025-09-13 7:19 ` [PATCH v4] " GuangFei Luo
2025-09-13 7:33 ` Greg KH
2025-09-13 7:56 ` [PATCH v5] " GuangFei Luo
2025-09-14 11:12 ` [PATCH v6] " GuangFei Luo
2025-09-23 2:38 ` GuangFei Luo
2025-09-23 11:48 ` Rafael J. Wysocki
2025-09-23 16:13 ` GuangFei Luo
2025-09-23 17:12 ` [PATCH " Rafael J. Wysocki
2025-09-23 16:18 ` GuangFei Luo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2025091354-query-oblivion-9d18@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=dan.carpenter@linaro.org \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lkp@intel.com \
--cc=luogf2025@163.com \
--cc=rafael@kernel.org \
--cc=sre@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox