Skip to content

Commit

Permalink
ACPI / battery: Fix acpi_battery_exit on acpi_battery_init_async errors
Browse files Browse the repository at this point in the history
The acpi_lock_battery_dir() / acpi_bus_register_driver() calls in
acpi_battery_init_async() may fail.

Check that they succeeded before undoing them.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Hans de Goede authored and Rafael J. Wysocki committed Apr 19, 2017
1 parent 8661423 commit bc39fbc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/acpi/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ MODULE_DESCRIPTION("ACPI Battery Driver");
MODULE_LICENSE("GPL");

static async_cookie_t async_cookie;
static bool battery_driver_registered;
static int battery_bix_broken_package;
static int battery_notification_delay_ms;
static unsigned int cache_time = 1000;
Expand Down Expand Up @@ -1329,6 +1330,7 @@ static void __init acpi_battery_init_async(void *unused, async_cookie_t cookie)
if (result < 0)
acpi_unlock_battery_dir(acpi_battery_dir);
#endif
battery_driver_registered = (result == 0);
}

static int __init acpi_battery_init(void)
Expand All @@ -1343,9 +1345,11 @@ static int __init acpi_battery_init(void)
static void __exit acpi_battery_exit(void)
{
async_synchronize_cookie(async_cookie + 1);
acpi_bus_unregister_driver(&acpi_battery_driver);
if (battery_driver_registered)
acpi_bus_unregister_driver(&acpi_battery_driver);
#ifdef CONFIG_ACPI_PROCFS_POWER
acpi_unlock_battery_dir(acpi_battery_dir);
if (acpi_battery_dir)
acpi_unlock_battery_dir(acpi_battery_dir);
#endif
}

Expand Down

0 comments on commit bc39fbc

Please sign in to comment.