Skip to contentSkip to conversation

ACPI: button: Only send `KEY_POWER` when suspended

PATCH In review Mario Limonciello 2 participants 2 messages Apr 4, 2025 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: button: Only send `KEY_POWER` when suspended

From: Mario Limonciello <[email protected]>

commit a7e23ec17feec ("ACPI: button: Install notifier for system events as well") modified the ACPI button behavior to send ACPI_BUTTON_NOTIFY_WAKE events. This caused a regression on a "Dell Optiplex 3040" sending KEY_POWER randomly at runtime.

Adjust logic so that ACPI_BUTTON_NOTIFY_WAKE can not send KEY_POWER unless system is suspended.

---
Cc: Yijun Shen <[email protected]>
Cc: Richard Gong <[email protected]>

---
 drivers/acpi/button.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/acpi/button.c +8 -6
index 90b09840536dd..515224943c3cf 100644
@@ -444,10 +444,18 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
 	struct input_dev *input;
 	int keycode;
 
+	button = acpi_driver_data(device);
+
 	switch (event) {
 	case ACPI_BUTTON_NOTIFY_STATUS:
+		acpi_pm_wakeup_event(&device->dev);
+		if (button->suspended)
+			return;
 		break;
 	case ACPI_BUTTON_NOTIFY_WAKE:
+		acpi_pm_wakeup_event(&device->dev);
+		if (!button->suspended)
+			return;
 		break;
 	default:
 		acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n",
@@ -455,12 +463,6 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
 		return;
 	}
 
-	acpi_pm_wakeup_event(&device->dev);
-
-	button = acpi_driver_data(device);
-	if (button->suspended)
-		return;
-
 	input = button->input;
 	keycode = test_bit(KEY_SLEEP, input->keybit) ? KEY_SLEEP : KEY_POWER;
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 33 lines · Mario Limonciello

From: Mario Limonciello <[email protected]>

commit a7e23ec17feec ("ACPI: button: Install notifier for system events as well") modified the ACPI button behavior to send ACPI_BUTTON_NOTIFY_WAKE events. This caused a regression on a "Dell Optiplex 3040" sending KEY_POWER randomly at runtime.

Adjust logic so that ACPI_BUTTON_NOTIFY_WAKE can not send KEY_POWER unless system is suspended.

---
Cc: Yijun Shen <[email protected]>
Cc: Richard Gong <[email protected]>

---
  drivers/acpi/button.c | 14 ++++++++------
  1 file changed, 8 insertions(+), 6 deletions(-)
drivers/acpi/button.c +2 -0
index 90b09840536dd..515224943c3cf 100644
@@ -444,10 +444,18 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
  	struct input_dev *input;
  	int keycode;
 
+	button = acpi_driver_data(device);
+
  	switch (event) {

drivers/acpi/button.c static void acpi_button_notify(acpi_handle handle, u32 event, void *data) · line 459

Quoted 10 lines
drivers/acpi/button.c +6 -0
  	case ACPI_BUTTON_NOTIFY_STATUS:
+		acpi_pm_wakeup_event(&device->dev);
+		if (button->suspended)
+			return;
  		break;
  	case ACPI_BUTTON_NOTIFY_WAKE:
+		acpi_pm_wakeup_event(&device->dev);
+		if (!button->suspended)
+			return;
  		break;

Thinking through this case, this probably isn't enough; it's going to lead to a situation that Yijun sees the system wake up followed by a KEY_POWER.

I'll spin a new version for testing.

Quoted 15 lines
drivers/acpi/button.c +0 -6
  	default:
  		acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n",
@@ -455,12 +463,6 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
  		return;
  	}
 
-	acpi_pm_wakeup_event(&device->dev);
-
-	button = acpi_driver_data(device);
-	if (button->suspended)
-		return;
-
  	input = button->input;
  	keycode = test_bit(KEY_SLEEP, input->keybit) ? KEY_SLEEP : KEY_POWER;