From nobody Sun May 24 20:34:04 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF12517557E; Thu, 21 May 2026 14:12:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779372765; cv=none; b=q3iMQYrchV+uI2775ILGd+iJpIfgRyOJWP3dTnUAWxDekNNX+zOCMXYxZy0krHOmpB0YLF0s1tm9mFfaD8E73iYbLeCAI/jR2Mgm0iAHPumiLZCdKKR7bqIAtlb/4DUs4buprZbj12AkuQdCRvrVkKl/aElt3/G8TpKdAhulx5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779372765; c=relaxed/simple; bh=7u3Xq1A5e3rekZV9p2VkqwzsCG4ESgwm0HFDzWKaeic=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=epkiNczMYM5O7+xJGm3Z5IQI/rEdPLskwpUJyrx1kStzqYDcDDpXsUQ9rsx1ORX4exkNjFgtpsFUJ0wM1Xg8WD/9MJhzbgGnGzaiirAXzyzGLRtKAIkrejsIEml6KoZeo7MP+7xbzsIHoT1ThmGOFufbgKSMt7fdoSg22yEQL0I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Pr7U/z8t; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Pr7U/z8t" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAFC61F000E9; Thu, 21 May 2026 14:12:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779372763; bh=L4pKi+6qO6Jsly0pKJhuJw33Q93Di3Ti7WaFJic1YfM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Pr7U/z8taWZuAg7/4HTQiHoK2jDn3VhFahpr6nB9+4XuyvyU0TR9N5wD4umwomV1J J03KtRMB+zWEv80TkFmr5FBwvU/+6430cMCJ0dLTZwIVAHgp3IS4TOjUSsa2sxEaqQ vSTjgK/+2SKtH45lEFhdbxzKN+bTWSFkg7ByAAieWvFLnKSYKdejmdk4hSosN9RKO2 zybInDcfE8RSndC2detECr+V5wIoE5SHHSA4TbJFaykGnw4DKvsnwm4FaoLJcRhv0S foeu8G2Q+/xEnSAtCE5aDMDXdA9yGvWhiePO4279vLhzFXu8BZ/A4PXzLrqY0T3lAp hd47Rc3HZAOtg== From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Andy Shevchenko , Hans de Goede , Armin Wolf Subject: [PATCH v1 03/17] ACPI: AC: Switch over to devres-based resource management Date: Thu, 21 May 2026 16:02:00 +0200 Message-ID: <3422377.44csPzL39Z@rafael.j.wysocki> Organization: Linux Kernel Development In-Reply-To: <4739447.LvFx2qVVIh@rafael.j.wysocki> References: <4739447.LvFx2qVVIh@rafael.j.wysocki> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Rafael J. Wysocki" 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 --- drivers/acpi/ac.c | 37 +++++++++++-------------------------- 1 file 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[] __ini= tconst =3D { static int acpi_ac_probe(struct platform_device *pdev) { struct power_supply_config psy_cfg =3D {}; + struct device *dev =3D &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; =20 - ac =3D kzalloc_obj(struct acpi_ac); + ac =3D devm_kzalloc(dev, sizeof(*ac), GFP_KERNEL); if (!ac) return -ENOMEM; =20 @@ -211,7 +212,7 @@ static int acpi_ac_probe(struct platform_device *pdev) =20 result =3D acpi_ac_get_state(ac); if (result) - goto err_release_ac; + return result; =20 psy_cfg.drv_data =3D ac; =20 @@ -220,33 +221,22 @@ static int acpi_ac_probe(struct platform_device *pdev) ac->charger_desc.properties =3D ac_props; ac->charger_desc.num_properties =3D ARRAY_SIZE(ac_props); ac->charger_desc.get_property =3D get_ac_property; - ac->charger =3D power_supply_register(&pdev->dev, - &ac->charger_desc, &psy_cfg); - if (IS_ERR(ac->charger)) { - result =3D PTR_ERR(ac->charger); - goto err_release_ac; - } + ac->charger =3D devm_power_supply_register(dev, &ac->charger_desc, &psy_c= fg); + if (IS_ERR(ac->charger)) + return PTR_ERR(ac->charger); =20 pr_info("AC Adapter [%s] (%s-line)\n", acpi_device_bid(adev), str_on_off(ac->state)); =20 + result =3D devm_acpi_install_notify_handler(dev, ACPI_ALL_NOTIFY, + acpi_ac_notify, ac); + if (result) + return result; + ac->battery_nb.notifier_call =3D acpi_ac_battery_notify; register_acpi_notifier(&ac->battery_nb); =20 - result =3D 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; } =20 #ifdef CONFIG_PM_SLEEP @@ -271,12 +261,7 @@ static void acpi_ac_remove(struct platform_device *pde= v) { struct acpi_ac *ac =3D platform_get_drvdata(pdev); =20 - 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); } =20 static struct platform_driver acpi_ac_driver =3D { --=20 2.51.0