[PATCH master] input: don't report depressed keys that were never pressed

Ahmad Fatoum a.fatoum at pengutronix.de
Sat Aug 24 13:02:50 PDT 2024


The USB keyboard driver remove callback sends a depress event for all
keys. This is relayed to all input notifiers and can confuse them by
reporting keys that were never pressed in the first place.

Instead of expecting input notifiers to keep track themselves of whether
keys have been pressed, have the core only report depress event for
previously pressed keys.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/input/input.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index 1a4792935114..e5509bf90d3e 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -44,10 +44,11 @@ void input_report_key_event(struct input_device *idev, unsigned int code, int va
 		pr_print(MSG_DEBUG, "Event. Dev: %s, Type: %d, Code: %d, Value: %d\n",
 			 dev_name(idev->parent), EV_KEY, code, value);
 
+	/* Only report depressed keys, if we registered them being pressed */
 	if (value)
 		set_bit(code, idev->keys);
-	else
-		clear_bit(code, idev->keys);
+	else if (!test_and_clear_bit(code, idev->keys))
+		return;
 
 	event.code = code;
 	event.value = value;
-- 
2.39.2




More information about the barebox mailing list