summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2026-05-21 17:02:00 +0300
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2026-05-25 17:43:51 +0300
commit026a7835bfda409661aafd5fcdf6b97878b21dc7 (patch)
treeda2aa0dff23e88604f6d3b60a1ab6518eada692f
parent198541ad53c0d0d891fedea4098f9953a0f566c0 (diff)
downloadlinux-026a7835bfda409661aafd5fcdf6b97878b21dc7.tar.xz
ACPI: AC: Switch over to devres-based resource management
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
-rw-r--r--drivers/acpi/ac.c37
1 files changed, 11 insertions, 26 deletions
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 27f31744f29e..f19d6dd43473 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -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 = {