From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Marek Vasut <marek.vasut@gmail.com>,
Russell King <linux@arm.linux.org.uk>,
Uli Luckas <u.luckas@road.de>,
Robert Jarzmik <robert.jarzmik@free.fr>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH v2 3/3] Input: matrix_keypad - only stop and start active device across sleep
Date: Fri, 27 Nov 2026 14:51:56 +0000 [thread overview]
Message-ID: <20261127145209.2884170-4-lee@kernel.org> (raw)
In-Reply-To: <20261127145209.2884170-1-lee@kernel.org>
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: bab7614d6d1b ("Input: add support for generic GPIO-based matrix keypad")
Closes: https://sashiko.dev/#/bug/linux-340f2a74-becb-415d-b1c2-6da8f05a8bd8
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
v1 => v2:
- Update the Fixes tag to commit bab7614d6d1b ("Input: add support for generic GPIO-based matrix keypad").
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 21c7df4e2e7b..370c08e6e264 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.839.g22a8290db9-goog
next prev parent reply other threads:[~2026-11-27 14:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 14:51 [PATCH v2 0/3] Input: Fix GPIO bounds, work teardown, and suspend bugs Lee Jones
2026-11-27 14:51 ` [PATCH v2 1/3] Input: matrix_keypad - validate GPIO counts against matrix limits Lee Jones
2026-11-27 14:51 ` [PATCH v2 2/3] Input: applespi - disable touchpad registration work on removal Lee Jones
2026-11-27 14:51 ` Lee Jones [this message]
2026-11-28 6:32 ` [PATCH v2 0/3] Input: Fix GPIO bounds, work teardown, and suspend bugs Dmitry Torokhov
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=20261127145209.2884170-4-lee@kernel.org \
--to=lee@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=marek.vasut@gmail.com \
--cc=robert.jarzmik@free.fr \
--cc=stable@vger.kernel.org \
--cc=u.luckas@road.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.