Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ACPI / battery: Fix acpi_battery_exit on acpi_battery_init_async errors

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>

authored by

Hans de Goede and committed by
Rafael J. Wysocki
bc39fbcf 8661423e

+6 -2
+6 -2
drivers/acpi/battery.c
··· 67 67 MODULE_LICENSE("GPL"); 68 68 69 69 static async_cookie_t async_cookie; 70 + static bool battery_driver_registered; 70 71 static int battery_bix_broken_package; 71 72 static int battery_notification_delay_ms; 72 73 static unsigned int cache_time = 1000; ··· 1330 1329 if (result < 0) 1331 1330 acpi_unlock_battery_dir(acpi_battery_dir); 1332 1331 #endif 1332 + battery_driver_registered = (result == 0); 1333 1333 } 1334 1334 1335 1335 static int __init acpi_battery_init(void) ··· 1345 1343 static void __exit acpi_battery_exit(void) 1346 1344 { 1347 1345 async_synchronize_cookie(async_cookie + 1); 1348 - acpi_bus_unregister_driver(&acpi_battery_driver); 1346 + if (battery_driver_registered) 1347 + acpi_bus_unregister_driver(&acpi_battery_driver); 1349 1348 #ifdef CONFIG_ACPI_PROCFS_POWER 1350 - acpi_unlock_battery_dir(acpi_battery_dir); 1349 + if (acpi_battery_dir) 1350 + acpi_unlock_battery_dir(acpi_battery_dir); 1351 1351 #endif 1352 1352 } 1353 1353