From: Hans de Goede <hdegoede@redhat.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>, Armin Wolf <W_Armin@gmx.de>
Cc: pali@kernel.org, dilinger@queued.net, lenb@kernel.org,
ilpo.jarvinen@linux.intel.com,
platform-driver-x86@vger.kernel.org, linux-acpi@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND v3 2/3] ACPI: battery: Fix possible crash when unregistering a battery hook
Date: Wed, 2 Oct 2024 14:35:13 +0200 [thread overview]
Message-ID: <ab75a39e-94e2-4b1a-9406-e05ebc816b03@redhat.com> (raw)
In-Reply-To: <CAJZ5v0gSYp5Umo-wsKvQ2Nff7YZ=_3-4bzG3TnKqMpHvxCmR5g@mail.gmail.com>
Hi,
On 2-Oct-24 2:08 PM, Rafael J. Wysocki wrote:
> On Tue, Oct 1, 2024 at 11:28 PM Armin Wolf <W_Armin@gmx.de> wrote:
>>
>> When a battery hook returns an error when adding a new battery, then
>> the battery hook is automatically unregistered.
>> However the battery hook provider cannot know that, so it will later
>> call battery_hook_unregister() on the already unregistered battery
>> hook, resulting in a crash.
>>
>> Fix this by using the list head to mark already unregistered battery
>> hooks as already being unregistered so that they can be ignored by
>> battery_hook_unregister().
>>
>> Fixes: fa93854f7a7e ("battery: Add the battery hooking API")
>> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
>
> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Hans, are you going to take this series or should I apply it?
AFAICT the patches don't really depend on each other, so my plan
was that you take patches 1-2 and I take patch 3 as a fix for
6.12-rc# .
Does that work for you ?
Regards,
Hans
>
>> ---
>> drivers/acpi/battery.c | 12 +++++++++---
>> 1 file changed, 9 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
>> index dda59ee5a11e..1c45ff6dbb83 100644
>> --- a/drivers/acpi/battery.c
>> +++ b/drivers/acpi/battery.c
>> @@ -715,7 +715,7 @@ static void battery_hook_unregister_unlocked(struct acpi_battery_hook *hook)
>> if (!hook->remove_battery(battery->bat, hook))
>> power_supply_changed(battery->bat);
>> }
>> - list_del(&hook->list);
>> + list_del_init(&hook->list);
>>
>> pr_info("extension unregistered: %s\n", hook->name);
>> }
>> @@ -723,7 +723,14 @@ static void battery_hook_unregister_unlocked(struct acpi_battery_hook *hook)
>> void battery_hook_unregister(struct acpi_battery_hook *hook)
>> {
>> mutex_lock(&hook_mutex);
>> - battery_hook_unregister_unlocked(hook);
>> + /*
>> + * Ignore already unregistered battery hooks. This might happen
>> + * if a battery hook was previously unloaded due to an error when
>> + * adding a new battery.
>> + */
>> + if (!list_empty(&hook->list))
>> + battery_hook_unregister_unlocked(hook);
>> +
>> mutex_unlock(&hook_mutex);
>> }
>> EXPORT_SYMBOL_GPL(battery_hook_unregister);
>> @@ -733,7 +740,6 @@ void battery_hook_register(struct acpi_battery_hook *hook)
>> struct acpi_battery *battery;
>>
>> mutex_lock(&hook_mutex);
>> - INIT_LIST_HEAD(&hook->list);
>> list_add(&hook->list, &battery_hook_list);
>> /*
>> * Now that the driver is registered, we need
>> --
>> 2.39.5
>>
>
next prev parent reply other threads:[~2024-10-02 12:35 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-01 21:28 [PATCH RESEND v3 0/3] platform/x86: dell-laptop: Battery hook fixes Armin Wolf
2024-10-01 21:28 ` [PATCH RESEND v3 1/3] ACPI: battery: Simplify battery hook locking Armin Wolf
2024-10-02 12:06 ` Rafael J. Wysocki
2024-10-02 14:48 ` Armin Wolf
2024-10-01 21:28 ` [PATCH RESEND v3 2/3] ACPI: battery: Fix possible crash when unregistering a battery hook Armin Wolf
2024-10-02 12:08 ` Rafael J. Wysocki
2024-10-02 12:35 ` Hans de Goede [this message]
2024-10-02 12:54 ` Rafael J. Wysocki
2024-10-02 17:54 ` Rafael J. Wysocki
2024-10-01 21:28 ` [PATCH RESEND v3 3/3] platform/x86: dell-laptop: Do not fail when encountering unsupported batteries Armin Wolf
2024-10-06 10:31 ` Hans de Goede
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=ab75a39e-94e2-4b1a-9406-e05ebc816b03@redhat.com \
--to=hdegoede@redhat.com \
--cc=W_Armin@gmx.de \
--cc=dilinger@queued.net \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pali@kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=rafael@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