ACPI: battery: Install Notify() handler directly
authorMichal Wilczynski <michal.wilczynski@intel.com>
Mon, 3 Jul 2023 08:02:48 +0000 (11:02 +0300)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 14 Jul 2023 16:58:34 +0000 (18:58 +0200)
Modify the ACPI battery driver to install its own Notify() handler
directly instead of providing an ACPI driver .notify() callback.

This will allow the ACPI driver .notify() callback to be eliminated and
it will allow the battery driver to be switched over to a platform one
in the future.

While at it, fix up whitespaces in acpi_battery_remove().

Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Michal Wilczynski <michal.wilczynski@intel.com>
[ rjw: Subject and changelog edits, whitespace adjustments ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/battery.c

index 9c67ed02d797347cb3bf500e415e9d7c7258f362..969bf81e8d546a76ad9be2151db8b5ffab4ae137 100644 (file)
@@ -1034,8 +1034,9 @@ static void acpi_battery_refresh(struct acpi_battery *battery)
 }
 
 /* Driver Interface */
-static void acpi_battery_notify(struct acpi_device *device, u32 event)
+static void acpi_battery_notify(acpi_handle handle, u32 event, void *data)
 {
+       struct acpi_device *device = data;
        struct acpi_battery *battery = acpi_driver_data(device);
        struct power_supply *old;
 
@@ -1212,13 +1213,22 @@ static int acpi_battery_add(struct acpi_device *device)
 
        device_init_wakeup(&device->dev, 1);
 
-       return result;
+       result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY,
+                                                acpi_battery_notify);
+       if (result)
+               goto fail_pm;
+
+       return 0;
 
+fail_pm:
+       device_init_wakeup(&device->dev, 0);
+       unregister_pm_notifier(&battery->pm_nb);
 fail:
        sysfs_remove_battery(battery);
        mutex_destroy(&battery->lock);
        mutex_destroy(&battery->sysfs_lock);
        kfree(battery);
+
        return result;
 }
 
@@ -1228,10 +1238,16 @@ static void acpi_battery_remove(struct acpi_device *device)
 
        if (!device || !acpi_driver_data(device))
                return;
-       device_init_wakeup(&device->dev, 0);
+
        battery = acpi_driver_data(device);
+
+       acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY,
+                                      acpi_battery_notify);
+
+       device_init_wakeup(&device->dev, 0);
        unregister_pm_notifier(&battery->pm_nb);
        sysfs_remove_battery(battery);
+
        mutex_destroy(&battery->lock);
        mutex_destroy(&battery->sysfs_lock);
        kfree(battery);
@@ -1264,11 +1280,9 @@ static struct acpi_driver acpi_battery_driver = {
        .name = "battery",
        .class = ACPI_BATTERY_CLASS,
        .ids = battery_device_ids,
-       .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
        .ops = {
                .add = acpi_battery_add,
                .remove = acpi_battery_remove,
-               .notify = acpi_battery_notify,
                },
        .drv.pm = &acpi_battery_pm,
 };