]> git.hungrycats.org Git - linux/commit
ACPI: battery: Fix possible crash when unregistering a battery hook
authorArmin Wolf <W_Armin@gmx.de>
Tue, 1 Oct 2024 21:28:34 +0000 (23:28 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Oct 2024 10:01:12 +0000 (12:01 +0200)
commitca26e8eed9c1c6651f51f7fa38fe444f8573cd1b
tree3c551767440f0e008dc81e7371a7efcd33d721d8
parent31ffdcb2b302306a0d8a64ba30896b8ac4b84473
ACPI: battery: Fix possible crash when unregistering a battery hook

[ Upstream commit 76959aff14a0012ad6b984ec7686d163deccdc16 ]

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>
Link: https://patch.msgid.link/20241001212835.341788-3-W_Armin@gmx.de
Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/acpi/battery.c