From: Zhian Liang <liangzhan5dev@gmail.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Zhian Liang <liangzhan5dev@gmail.com>
Subject: [PATCH 2/2] Input: tca8418_keypad - fix race condition in interrupt handler
Date: Fri, 4 Sep 2026 03:29:42 +0800 [thread overview]
Message-ID: <20260903192942.21906-2-liangzhan5dev@gmail.com> (raw)
In-Reply-To: <20260903192942.21906-1-liangzhan5dev@gmail.com>
There is a race condition in tca8418_irq_handler() where a new key event
can be lost if it arrives after the FIFO is drained but before the
interrupt status register is cleared.
Fix this by re-reading INT_STAT after draining the FIFO and repeating
the process if K_INT is still asserted. This ensures the FIFO is truly
empty before clearing interrupts.
The FIFO depth is 10 events, so a loop limit of 16 provides sufficient
margin while preventing infinite loops in case of hardware misbehavior.
Signed-off-by: Zhian Liang <liangzhan5dev@gmail.com>
---
drivers/input/keyboard/tca8418_keypad.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/input/keyboard/tca8418_keypad.c b/drivers/input/keyboard/tca8418_keypad.c
index 9f0aace6bd21..0952370c0636 100644
--- a/drivers/input/keyboard/tca8418_keypad.c
+++ b/drivers/input/keyboard/tca8418_keypad.c
@@ -212,6 +212,7 @@ static irqreturn_t tca8418_irq_handler(int irq, void *dev_id)
struct tca8418_keypad *keypad_data = dev_id;
u8 reg;
int error;
+ int max_loops = 16;
error = tca8418_read_byte(keypad_data, REG_INT_STAT, ®);
if (error) {
@@ -225,9 +226,19 @@ static irqreturn_t tca8418_irq_handler(int irq, void *dev_id)
if (reg & INT_STAT_OVR_FLOW_INT)
dev_warn(&keypad_data->client->dev, "overflow occurred\n");
+ do {
+ if (reg & INT_STAT_K_INT)
+ tca8418_read_keypad(keypad_data);
+
+ /* Re-read interrupt status to check for new events */
+ error = tca8418_read_byte(keypad_data, REG_INT_STAT, ®);
+ if (error) {
+ dev_err(&keypad_data->client->dev,
+ "unable to re-read REG_INT_STAT\n");
+ return IRQ_HANDLED;
+ }
- if (reg & INT_STAT_K_INT)
- tca8418_read_keypad(keypad_data);
+ } while ((reg & INT_STAT_K_INT) && --max_loops);
/* Clear all interrupts, even IRQs we didn't check (GPI, CAD, LCK) */
reg = 0xff;
--
2.34.1
next prev parent reply other threads:[~2026-09-03 19:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 19:29 [PATCH 1/2] Input: tca8418_keypad - Add devm cleanup to disable interrupts on unload Zhian Liang
2026-09-03 19:29 ` Zhian Liang [this message]
2026-09-03 21:06 ` [PATCH v2] " Zhian Liang
2026-09-05 9:37 ` [PATCH 1/2] " 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=20260903192942.21906-2-liangzhan5dev@gmail.com \
--to=liangzhan5dev@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@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®