]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ACPI: AC: Switch over to devres-based resource management
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 21 May 2026 14:02:00 +0000 (16:02 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 25 May 2026 14:43:51 +0000 (16:43 +0200)
Use devm_kzalloc() for allocating memory, devm_power_supply_register()
for registering a power supply class device and the newly introduced
devm_acpi_install_notify_handler() for installing an ACPI notify handler.

Note that the code ordering change related to the third of the above
modifications does not matter because there is no order dependency
between the battery notifier and the ACPI notify handler.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/3422377.44csPzL39Z@rafael.j.wysocki
drivers/acpi/ac.c

index 27f31744f29e23e6e921cd5b68d69d2f77b7b8a4..f19d6dd43473a2d97ca2a4a68813fcb4336d1e4c 100644 (file)
@@ -193,6 +193,7 @@ static const struct dmi_system_id ac_dmi_table[]  __initconst = {
 static int acpi_ac_probe(struct platform_device *pdev)
 {
        struct power_supply_config psy_cfg = {};
+       struct device *dev = &pdev->dev;
        struct acpi_device *adev;
        struct acpi_ac *ac;
        int result;
@@ -201,7 +202,7 @@ static int acpi_ac_probe(struct platform_device *pdev)
        if (!adev)
                return -ENODEV;
 
-       ac = kzalloc_obj(struct acpi_ac);
+       ac = devm_kzalloc(dev, sizeof(*ac), GFP_KERNEL);
        if (!ac)
                return -ENOMEM;
 
@@ -211,7 +212,7 @@ static int acpi_ac_probe(struct platform_device *pdev)
 
        result = acpi_ac_get_state(ac);
        if (result)
-               goto err_release_ac;
+               return result;
 
        psy_cfg.drv_data = ac;
 
@@ -220,33 +221,22 @@ static int acpi_ac_probe(struct platform_device *pdev)
        ac->charger_desc.properties = ac_props;
        ac->charger_desc.num_properties = ARRAY_SIZE(ac_props);
        ac->charger_desc.get_property = get_ac_property;
-       ac->charger = power_supply_register(&pdev->dev,
-                                           &ac->charger_desc, &psy_cfg);
-       if (IS_ERR(ac->charger)) {
-               result = PTR_ERR(ac->charger);
-               goto err_release_ac;
-       }
+       ac->charger = devm_power_supply_register(dev, &ac->charger_desc, &psy_cfg);
+       if (IS_ERR(ac->charger))
+               return PTR_ERR(ac->charger);
 
        pr_info("AC Adapter [%s] (%s-line)\n", acpi_device_bid(adev),
                str_on_off(ac->state));
 
+       result = devm_acpi_install_notify_handler(dev, ACPI_ALL_NOTIFY,
+                                                 acpi_ac_notify, ac);
+       if (result)
+               return result;
+
        ac->battery_nb.notifier_call = acpi_ac_battery_notify;
        register_acpi_notifier(&ac->battery_nb);
 
-       result = acpi_dev_install_notify_handler(adev, ACPI_ALL_NOTIFY,
-                                                acpi_ac_notify, ac);
-       if (result)
-               goto err_unregister;
-
        return 0;
-
-err_unregister:
-       power_supply_unregister(ac->charger);
-       unregister_acpi_notifier(&ac->battery_nb);
-err_release_ac:
-       kfree(ac);
-
-       return result;
 }
 
 #ifdef CONFIG_PM_SLEEP
@@ -271,12 +261,7 @@ static void acpi_ac_remove(struct platform_device *pdev)
 {
        struct acpi_ac *ac = platform_get_drvdata(pdev);
 
-       acpi_dev_remove_notify_handler(ac->device, ACPI_ALL_NOTIFY,
-                                      acpi_ac_notify);
-       power_supply_unregister(ac->charger);
        unregister_acpi_notifier(&ac->battery_nb);
-
-       kfree(ac);
 }
 
 static struct platform_driver acpi_ac_driver = {