From nobody Mon Jun 8 05:25:47 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 7D9EE289E13; Mon, 1 Jun 2026 17:13:18 +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=1780333999; cv=none; b=nil/4YNneSk9jQc7G/2+St3U4ryNuST+3sKFObWDUfkzprR/WyalsMTWRk0Jf8i3U5fxBIciidhiWXAiO03luC8hzTGUfBEwoDnO+8YzrFYkhrK7aAnnZoQ5hdKQ64KAl48XAs1IAvqI0tkyN3gtAHC26AT8CpJ96oZUCSYxzqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780333999; c=relaxed/simple; bh=iwtZnaR/gdpS0mkrNNIlB72LQDYz+3SdLS5BoI0S+/I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qiG8Mab3UiM/Njs36o42NRifbhVi5DLm4iMY76O1dIKoCLO+6uKv83/wKpq1maquyb8hcVKdwpRr3nFVevgxTeWbY11wBORGLJgHdygpq7L4IVFHxbVns79j3AZyGmYRdbtapcWyy0aKDMsaHCz0mkUvMzy/eb+iQ5HR1K3eX/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bP3W7ebV; 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="bP3W7ebV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B7441F00893; Mon, 1 Jun 2026 17:13:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780333998; bh=0TvUtgnJYq2bcE49nBgwYuOC7Ri6DJxLQQ7z6kwGp4E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bP3W7ebVA/pyXmpdJ63+Hk5Pq1cntZJogaheTCg4S6OzXU1/8rAzIDVkUPazWqwPD Etfjq9IdupdzcRbe+mTHxMjZm5BcbD7SpwrTBGHlqR35l9QNFQFBCN/KbgIT/5Kbg+ Ncgf2La3X4LkFkPZq9KZQKbYKuSmMLRGQDXw3eaWDxMxBK2S+2p0r740Rbja7rs34c SG+OFtN6sk0wd8kEjVs12RKCi+mWUOOguHYYwln0h57fBoYI6deoKk6li0IMYaOrdB t77TC3Q95DIMLI5PNiVIY3XrrtbSRHpCs9rRY9A6ncMCgvbKG/IcwxYzDQsRWNtAms xtWztxVaN2Shw== From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML Subject: [PATCH v1 15/15] ACPI: button: Switch over to devres-based resource management Date: Mon, 01 Jun 2026 19:12:58 +0200 Message-ID: <2283436.Mh6RI2rZIc@rafael.j.wysocki> Organization: Linux Kernel Development In-Reply-To: <12913564.O9o76ZdvQC@rafael.j.wysocki> References: <12913564.O9o76ZdvQC@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" Switch over the ACPI button driver to devres-based resource management by making the following changes: * Use devm_kzalloc() for allocating button object memory. * Use devm_input_allocate_device() for allocating the input class device object. * Turn acpi_lid_remove_fs() into a devm cleanup action added by devm_acpi_lid_add_fs() which is a new wrapper around acpi_lid_add_fs(). * Add devm_acpi_button_init_wakeup() for initializing the wakeup source and make it add a custom devm action that will automatically remove the wakeup source registered by it. * Turn acpi_button_remove_event_handler() into a devm cleanup action added by devm_acpi_button_add_event_handler() which is a new wrapper around acpi_button_add_event_handler(). No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/button.c | 101 ++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c index 8a56780e13da..154b17a8ea25 100644 --- a/drivers/acpi/button.c +++ b/drivers/acpi/button.c @@ -340,8 +340,9 @@ static int acpi_lid_add_fs(struct acpi_button *button) return -ENODEV; } =20 -static void acpi_lid_remove_fs(struct acpi_button *button) +static void acpi_lid_remove_fs(void *data) { + struct acpi_button *button =3D data; struct acpi_device *device =3D button->adev; =20 remove_proc_entry(ACPI_BUTTON_FILE_STATE, @@ -355,6 +356,17 @@ static void acpi_lid_remove_fs(struct acpi_button *but= ton) acpi_button_dir =3D NULL; } =20 +static int devm_acpi_lid_add_fs(struct device *dev, struct acpi_button *bu= tton) +{ + int ret; + + ret =3D acpi_lid_add_fs(button); + if (ret) + return ret; + + return devm_add_action_or_reset(dev, acpi_lid_remove_fs, button); +} + static acpi_handle saved_lid_handle; static DEFINE_MUTEX(acpi_lid_lock); =20 @@ -530,8 +542,20 @@ static acpi_notify_handler acpi_button_notify_handler(= struct acpi_button *button return acpi_button_notify; } =20 -static void acpi_button_remove_event_handler(struct acpi_button *button) +static void acpi_button_wakeup_cleanup(void *data) +{ + device_init_wakeup(data, false); +} + +static int devm_acpi_button_init_wakeup(struct device *dev) { + device_init_wakeup(dev, true); + return devm_add_action_or_reset(dev, acpi_button_wakeup_cleanup, dev); +} + +static void acpi_button_remove_event_handler(void *data) +{ + struct acpi_button *button =3D data; struct acpi_device *adev =3D button->adev; =20 switch (adev->device_type) { @@ -606,6 +630,19 @@ static int acpi_button_add_event_handler(struct acpi_b= utton *button) return 0; } =20 +static int devm_acpi_button_add_event_handler(struct device *dev, + struct acpi_button *button) +{ + int ret; + + ret =3D acpi_button_add_event_handler(button); + if (ret) + return ret; + + return devm_add_action_or_reset(dev, acpi_button_remove_event_handler, + button); +} + static int acpi_button_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -625,7 +662,7 @@ static int acpi_button_probe(struct platform_device *pd= ev) lid_init_state =3D=3D ACPI_BUTTON_LID_INIT_DISABLED) return -ENODEV; =20 - button =3D kzalloc_obj(struct acpi_button); + button =3D devm_kzalloc(dev, sizeof(*button), GFP_KERNEL); if (!button) return -ENOMEM; =20 @@ -633,11 +670,10 @@ static int acpi_button_probe(struct platform_device *= pdev) =20 button->dev =3D dev; button->adev =3D device; - input =3D input_allocate_device(); - if (!input) { - error =3D -ENOMEM; - goto err_free_button; - } + input =3D devm_input_allocate_device(dev); + if (!input) + return -ENOMEM; + button->input =3D input; button->type =3D button_type; =20 @@ -649,11 +685,10 @@ static int acpi_button_probe(struct platform_device *= pdev) input_set_capability(input, EV_SW, SW_LID); input->open =3D acpi_lid_input_open; =20 - error =3D acpi_lid_add_fs(button); - if (error) { - input_free_device(input); - goto err_free_button; - } + error =3D devm_acpi_lid_add_fs(dev, button); + if (error) + return error; + break; =20 case ACPI_BUTTON_TYPE_POWER: @@ -672,7 +707,6 @@ static int acpi_button_probe(struct platform_device *pd= ev) break; =20 default: - input_free_device(input); return dev_err_probe(dev, -ENODEV, "Unrecognized button type\n"); } =20 @@ -686,16 +720,16 @@ static int acpi_button_probe(struct platform_device *= pdev) =20 input_set_drvdata(input, button); error =3D input_register_device(input); - if (error) { - input_free_device(input); - goto err_remove_fs; - } + if (error) + return error; =20 - device_init_wakeup(button->dev, true); + error =3D devm_acpi_button_init_wakeup(dev); + if (error) + return error; =20 - error =3D acpi_button_add_event_handler(button); + error =3D devm_acpi_button_add_event_handler(dev, button); if (error) - goto err_input_unregister; + return error; =20 if (button_type =3D=3D ACPI_BUTTON_TYPE_LID) { /* @@ -706,37 +740,16 @@ static int acpi_button_probe(struct platform_device *= pdev) } =20 pr_info("%s [%s]\n", input->name, acpi_device_bid(device)); - return 0; =20 -err_input_unregister: - device_init_wakeup(button->dev, false); - input_unregister_device(input); -err_remove_fs: - if (button_type =3D=3D ACPI_BUTTON_TYPE_LID) - acpi_lid_remove_fs(button); - -err_free_button: - kfree(button); - return error; + return 0; } =20 static void acpi_button_remove(struct platform_device *pdev) { struct acpi_button *button =3D platform_get_drvdata(pdev); - struct acpi_device *adev =3D button->adev; - - if (button->type =3D=3D ACPI_BUTTON_TYPE_LID) - acpi_lid_forget(adev); - - acpi_button_remove_event_handler(button); =20 - device_init_wakeup(button->dev, false); - - input_unregister_device(button->input); if (button->type =3D=3D ACPI_BUTTON_TYPE_LID) - acpi_lid_remove_fs(button); - - kfree(button); + acpi_lid_forget(button->adev); } =20 static int param_set_lid_init_state(const char *val, --=20 2.51.0