[PATCH 04/10] Input: matrix_keypad - only stop and start active device across sleep
From: Lee Jones
Date: Mon Nov 23 2026 - 13:32:45 EST
matrix_keypad_suspend() and matrix_keypad_resume() unconditionally call
matrix_keypad_stop() and matrix_keypad_start() without holding
input_dev->mutex or checking whether the input device is active.
When the keypad has no open users (or is inhibited), row interrupts are
already disabled and keypad->stopped is true. Suspending calls
disable_row_irqs() a second time, unbalancing the IRQ disable depth, and
resuming clears keypad->stopped and schedules keypad->work. If the
device is subsequently unbound while still unopened, Input core skips
the close callback (matrix_keypad_stop()) during unregistration, leaving
keypad->work pending or running after devres frees struct matrix_keypad.
Acquire input_dev->mutex in both sleep callbacks and only stop or start
scanning when input_device_enabled() is true.
Fixes: 7d0f351da460 ("Input: matrix_keypad - switch to using managed resources")
Closes: https://sashiko.dev/#/bug/linux-340f2a74-becb-415d-b1c2-6da8f05a8bd8
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/input/keyboard/matrix_keypad.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
index c2f839a3de90..81507e2a6126 100644
--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -268,7 +268,10 @@ static int matrix_keypad_suspend(struct device *dev)
struct platform_device *pdev = to_platform_device(dev);
struct matrix_keypad *keypad = platform_get_drvdata(pdev);
- matrix_keypad_stop(keypad->input_dev);
+ guard(mutex)(&keypad->input_dev->mutex);
+
+ if (input_device_enabled(keypad->input_dev))
+ matrix_keypad_stop(keypad->input_dev);
if (device_may_wakeup(&pdev->dev))
matrix_keypad_enable_wakeup(keypad);
@@ -281,10 +284,13 @@ static int matrix_keypad_resume(struct device *dev)
struct platform_device *pdev = to_platform_device(dev);
struct matrix_keypad *keypad = platform_get_drvdata(pdev);
+ guard(mutex)(&keypad->input_dev->mutex);
+
if (device_may_wakeup(&pdev->dev))
matrix_keypad_disable_wakeup(keypad);
- matrix_keypad_start(keypad->input_dev);
+ if (input_device_enabled(keypad->input_dev))
+ matrix_keypad_start(keypad->input_dev);
return 0;
}
--
2.56.1.750.gf70dc682cf-goog