From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Linux ACPI <linux-acpi@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH v1 15/15] ACPI: button: Switch over to devres-based resource management
Date: Mon, 01 Jun 2026 19:12:58 +0200 [thread overview]
Message-ID: <2283436.Mh6RI2rZIc@rafael.j.wysocki> (raw)
In-Reply-To: <12913564.O9o76ZdvQC@rafael.j.wysocki>
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
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 <rafael.j.wysocki@intel.com>
---
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;
}
-static void acpi_lid_remove_fs(struct acpi_button *button)
+static void acpi_lid_remove_fs(void *data)
{
+ struct acpi_button *button = data;
struct acpi_device *device = button->adev;
remove_proc_entry(ACPI_BUTTON_FILE_STATE,
@@ -355,6 +356,17 @@ static void acpi_lid_remove_fs(struct acpi_button *button)
acpi_button_dir = NULL;
}
+static int devm_acpi_lid_add_fs(struct device *dev, struct acpi_button *button)
+{
+ int ret;
+
+ ret = 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);
@@ -530,8 +542,20 @@ static acpi_notify_handler acpi_button_notify_handler(struct acpi_button *button
return acpi_button_notify;
}
-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 = data;
struct acpi_device *adev = button->adev;
switch (adev->device_type) {
@@ -606,6 +630,19 @@ static int acpi_button_add_event_handler(struct acpi_button *button)
return 0;
}
+static int devm_acpi_button_add_event_handler(struct device *dev,
+ struct acpi_button *button)
+{
+ int ret;
+
+ ret = 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 = &pdev->dev;
@@ -625,7 +662,7 @@ static int acpi_button_probe(struct platform_device *pdev)
lid_init_state == ACPI_BUTTON_LID_INIT_DISABLED)
return -ENODEV;
- button = kzalloc_obj(struct acpi_button);
+ button = devm_kzalloc(dev, sizeof(*button), GFP_KERNEL);
if (!button)
return -ENOMEM;
@@ -633,11 +670,10 @@ static int acpi_button_probe(struct platform_device *pdev)
button->dev = dev;
button->adev = device;
- input = input_allocate_device();
- if (!input) {
- error = -ENOMEM;
- goto err_free_button;
- }
+ input = devm_input_allocate_device(dev);
+ if (!input)
+ return -ENOMEM;
+
button->input = input;
button->type = button_type;
@@ -649,11 +685,10 @@ static int acpi_button_probe(struct platform_device *pdev)
input_set_capability(input, EV_SW, SW_LID);
input->open = acpi_lid_input_open;
- error = acpi_lid_add_fs(button);
- if (error) {
- input_free_device(input);
- goto err_free_button;
- }
+ error = devm_acpi_lid_add_fs(dev, button);
+ if (error)
+ return error;
+
break;
case ACPI_BUTTON_TYPE_POWER:
@@ -672,7 +707,6 @@ static int acpi_button_probe(struct platform_device *pdev)
break;
default:
- input_free_device(input);
return dev_err_probe(dev, -ENODEV, "Unrecognized button type\n");
}
@@ -686,16 +720,16 @@ static int acpi_button_probe(struct platform_device *pdev)
input_set_drvdata(input, button);
error = input_register_device(input);
- if (error) {
- input_free_device(input);
- goto err_remove_fs;
- }
+ if (error)
+ return error;
- device_init_wakeup(button->dev, true);
+ error = devm_acpi_button_init_wakeup(dev);
+ if (error)
+ return error;
- error = acpi_button_add_event_handler(button);
+ error = devm_acpi_button_add_event_handler(dev, button);
if (error)
- goto err_input_unregister;
+ return error;
if (button_type == ACPI_BUTTON_TYPE_LID) {
/*
@@ -706,37 +740,16 @@ static int acpi_button_probe(struct platform_device *pdev)
}
pr_info("%s [%s]\n", input->name, acpi_device_bid(device));
- return 0;
-err_input_unregister:
- device_init_wakeup(button->dev, false);
- input_unregister_device(input);
-err_remove_fs:
- if (button_type == ACPI_BUTTON_TYPE_LID)
- acpi_lid_remove_fs(button);
-
-err_free_button:
- kfree(button);
- return error;
+ return 0;
}
static void acpi_button_remove(struct platform_device *pdev)
{
struct acpi_button *button = platform_get_drvdata(pdev);
- struct acpi_device *adev = button->adev;
-
- if (button->type == ACPI_BUTTON_TYPE_LID)
- acpi_lid_forget(adev);
-
- acpi_button_remove_event_handler(button);
- device_init_wakeup(button->dev, false);
-
- input_unregister_device(button->input);
if (button->type == ACPI_BUTTON_TYPE_LID)
- acpi_lid_remove_fs(button);
-
- kfree(button);
+ acpi_lid_forget(button->adev);
}
static int param_set_lid_init_state(const char *val,
--
2.51.0
prev parent reply other threads:[~2026-06-01 17:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-01 16:53 [PATCH v1 00/15] ACPI: button: Cleanups and conversion to using devm Rafael J. Wysocki
2026-06-01 16:55 ` [PATCH v1 01/15] ACPI: button: Fix lid_device value leak past driver removal Rafael J. Wysocki
2026-06-01 16:55 ` [PATCH v1 02/15] ACPI: button: Pass ACPI handle to acpi_lid_evaluate_state() Rafael J. Wysocki
2026-06-01 16:56 ` [PATCH v1 03/15] ACPI: button: Improve warning message regarding lid state Rafael J. Wysocki
2026-06-01 16:58 ` [PATCH v1 04/15] ACPI: button: Use bool for representing boolean values Rafael J. Wysocki
2026-06-01 16:59 ` [PATCH v1 05/15] ACPI: button: Eliminate ternary operator from acpi_lid_evaluate_state() Rafael J. Wysocki
2026-06-01 17:00 ` [PATCH v1 06/15] ACPI: button: Change return type of two functions to void Rafael J. Wysocki
2026-06-01 17:00 ` [PATCH v1 07/15] ACPI: button: Eliminate redundant conditional statement Rafael J. Wysocki
2026-06-01 17:01 ` [PATCH v1 08/15] ACPI: button: Use local pointer to platform device dev field in probe Rafael J. Wysocki
2026-06-01 17:03 ` [PATCH v1 09/15] ACPI: button: Rework device verification during probe Rafael J. Wysocki
2026-06-01 17:04 ` [PATCH v1 10/15] ACPI: button: Drop redundant variable from acpi_button_probe() Rafael J. Wysocki
2026-06-01 17:05 ` [PATCH v1 11/15] ACPI: button: Merge two switch () statements in acpi_button_probe() Rafael J. Wysocki
2026-06-01 17:07 ` [PATCH v1 12/15] ACPI: button: Clean up adding and removing lid procfs interface Rafael J. Wysocki
2026-06-01 17:07 ` [PATCH v1 13/15] ACPI: button: Use string literals for generating netlink messages Rafael J. Wysocki
2026-06-01 17:12 ` [PATCH v1 14/15] ACPI: button: Reorganize installing and removing event handlers Rafael J. Wysocki
2026-06-01 17:12 ` Rafael J. Wysocki [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2283436.Mh6RI2rZIc@rafael.j.wysocki \
--to=rafael@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®