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 12/15] ACPI: button: Clean up adding and removing lid procfs interface
Date: Mon, 01 Jun 2026 19:07:14 +0200 [thread overview]
Message-ID: <1869050.VLH7GnMWUR@rafael.j.wysocki> (raw)
In-Reply-To: <12913564.O9o76ZdvQC@rafael.j.wysocki>
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
The procfs interface is only used with lid devices which only becomes
clear after looking into the function bodies of acpi_button_add_fs()
and acpi_button_remove_fs(). Moreover, the only error code returned
by the former of these functions is -ENODEV, so the ret local variable
in it is redundant, and the return type of the latter one can be changed
to void.
Accordingly, rename these functions to acpi_button_add_fs() and
acpi_button_remove_fs(), respectively, move the button->type checks
against ACPI_BUTTON_TYPE_LID from them to their callers, and make
code simplifications as per the above.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/button.c | 54 ++++++++++++++++---------------------------
1 file changed, 20 insertions(+), 34 deletions(-)
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index c035741e5abf..3327ee8132ad 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -292,15 +292,10 @@ static int __maybe_unused acpi_button_state_seq_show(struct seq_file *seq,
return 0;
}
-static int acpi_button_add_fs(struct acpi_button *button)
+static int acpi_lid_add_fs(struct acpi_button *button)
{
struct acpi_device *device = button->adev;
struct proc_dir_entry *entry = NULL;
- int ret = 0;
-
- /* procfs I/F for ACPI lid device only */
- if (button->type != ACPI_BUTTON_TYPE_LID)
- return 0;
if (acpi_button_dir || acpi_lid_dir) {
pr_info("More than one Lid device found!\n");
@@ -314,33 +309,25 @@ static int acpi_button_add_fs(struct acpi_button *button)
/* create /proc/acpi/button/lid */
acpi_lid_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir);
- if (!acpi_lid_dir) {
- ret = -ENODEV;
+ if (!acpi_lid_dir)
goto remove_button_dir;
- }
/* create /proc/acpi/button/lid/LID/ */
acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), acpi_lid_dir);
- if (!acpi_device_dir(device)) {
- ret = -ENODEV;
+ if (!acpi_device_dir(device))
goto remove_lid_dir;
- }
/* create /proc/acpi/button/lid/LID/state */
entry = proc_create_single_data(ACPI_BUTTON_FILE_STATE, S_IRUGO,
acpi_device_dir(device), acpi_button_state_seq_show,
button);
- if (!entry) {
- ret = -ENODEV;
+ if (!entry)
goto remove_dev_dir;
- }
-done:
- return ret;
+ return 0;
remove_dev_dir:
- remove_proc_entry(acpi_device_bid(device),
- acpi_lid_dir);
+ remove_proc_entry(acpi_device_bid(device), acpi_lid_dir);
acpi_device_dir(device) = NULL;
remove_lid_dir:
remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir);
@@ -348,16 +335,13 @@ static int acpi_button_add_fs(struct acpi_button *button)
remove_button_dir:
remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
acpi_button_dir = NULL;
- goto done;
+ return -ENODEV;
}
-static int acpi_button_remove_fs(struct acpi_button *button)
+static void acpi_lid_remove_fs(struct acpi_button *button)
{
struct acpi_device *device = button->adev;
- if (button->type != ACPI_BUTTON_TYPE_LID)
- return 0;
-
remove_proc_entry(ACPI_BUTTON_FILE_STATE,
acpi_device_dir(device));
remove_proc_entry(acpi_device_bid(device),
@@ -367,8 +351,6 @@ static int acpi_button_remove_fs(struct acpi_button *button)
acpi_lid_dir = NULL;
remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
acpi_button_dir = NULL;
-
- return 0;
}
static acpi_handle saved_lid_handle;
@@ -588,6 +570,12 @@ static int acpi_button_probe(struct platform_device *pdev)
handler = acpi_lid_notify;
sprintf(class, "%s/%s",
ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
+
+ error = acpi_lid_add_fs(button);
+ if (error) {
+ input_free_device(input);
+ goto err_free_button;
+ }
break;
case ACPI_BUTTON_TYPE_POWER:
@@ -614,12 +602,6 @@ static int acpi_button_probe(struct platform_device *pdev)
return dev_err_probe(dev, -ENODEV, "Unrecognized button type\n");
}
- error = acpi_button_add_fs(button);
- if (error) {
- input_free_device(input);
- goto err_free_button;
- }
-
snprintf(button->phys, sizeof(button->phys), "%s/button/input0",
acpi_device_hid(device));
@@ -689,7 +671,9 @@ static int acpi_button_probe(struct platform_device *pdev)
device_init_wakeup(button->dev, false);
input_unregister_device(input);
err_remove_fs:
- acpi_button_remove_fs(button);
+ if (button_type == ACPI_BUTTON_TYPE_LID)
+ acpi_lid_remove_fs(button);
+
err_free_button:
kfree(button);
memset(acpi_device_class(device), 0, sizeof(acpi_device_class));
@@ -730,8 +714,10 @@ static void acpi_button_remove(struct platform_device *pdev)
device_init_wakeup(button->dev, false);
- acpi_button_remove_fs(button);
input_unregister_device(button->input);
+ if (button->type == ACPI_BUTTON_TYPE_LID)
+ acpi_lid_remove_fs(button);
+
kfree(button);
memset(acpi_device_class(adev), 0, sizeof(acpi_device_class));
--
2.51.0
next 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 ` Rafael J. Wysocki [this message]
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 ` [PATCH v1 15/15] ACPI: button: Switch over to devres-based resource management Rafael J. Wysocki
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=1869050.VLH7GnMWUR@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