[PATCH] Input: atkbd - rate-limit unknown key warnings

Zhang Heng posted 1 patch 3 days, 5 hours ago
drivers/input/keyboard/atkbd.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
[PATCH] Input: atkbd - rate-limit unknown key warnings
Posted by Zhang Heng 3 days, 5 hours ago
Replace dev_warn() with dev_warn_ratelimited() for unmapped scancode
warnings, matching the existing rate-limited handling of spurious
ACK/NAK events in the same function. 

Link: https://bugzilla.kernel.org/show_bug.cgi?id=221214
Signed-off-by: Zhang Heng <zhangheng@kylinos.cn>
---
 drivers/input/keyboard/atkbd.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index 93650c98206d..26523329040b 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -497,13 +497,11 @@ static void atkbd_receive_byte(struct ps2dev *ps2dev, u8 data)
 	case ATKBD_KEY_NULL:
 		break;
 	case ATKBD_KEY_UNKNOWN:
-		dev_warn(&serio->dev,
-			 "Unknown key %s (%s set %d, code %#x on %s).\n",
-			 atkbd->release ? "released" : "pressed",
-			 atkbd->translated ? "translated" : "raw",
-			 atkbd->set, code, serio->phys);
-		dev_warn(&serio->dev,
-			 "Use 'setkeycodes %s%02x <keycode>' to make it known.\n",
-			 code & 0x80 ? "e0" : "", code & 0x7f);
+		dev_warn_ratelimited(&serio->dev,
+				     "Unknown key %s (%s set %d, code %#x on %s); use 'setkeycodes %s%02x <keycode>' to make it known.\n",
+				     atkbd->release ? "released" : "pressed",
+				     atkbd->translated ? "translated" : "raw",
+				     atkbd->set, code, serio->phys,
+				     code & 0x80 ? "e0" : "", code & 0x7f);
 		input_sync(dev);
 		break;
-- 
2.25.1
Re: [PATCH] Input: atkbd - rate-limit unknown key warnings
Posted by Dmitry Torokhov 3 days, 2 hours ago
Hi Zhang,

On Mon, Sep 21, 2026 at 09:19:34PM +0800, Zhang Heng wrote:
> Replace dev_warn() with dev_warn_ratelimited() for unmapped scancode
> warnings, matching the existing rate-limited handling of spurious
> ACK/NAK events in the same function. 

I do not think this is needed. Unlike spurious NAK/ACKs pressing keys
are initiated by a person and events are naturally rate-limited.

The solution is to indeed map the key to do nothing:

	KEYBOARD_KEY_xx=unknown

Userspace ignores KEY_UNKNOWN events and there are no dmesg logs either.

Thanks.

-- 
Dmitry
Re: [PATCH] Input: atkbd - rate-limit unknown key warnings
Posted by Zhang Heng 2 days, 16 hours ago
Thanks for your reply. This fix should be handled in userspace. It’s 
just that for ordinary users, they see a lot of warning messages after 
pressing keys, so perhaps it would be better to limit the output. I also 
agree with you that this patch is not necessary—after all, the benefit 
of this patch is indeed limited. If the patch is not merged, I’m fine 
with that.
Re: [PATCH] Input: atkbd - rate-limit unknown key warnings
Posted by Dmitry Torokhov 2 days, 15 hours ago
On Tue, Sep 22, 2026 at 10:12:15AM +0800, Zhang Heng wrote:
> Thanks for your reply. This fix should be handled in userspace. It’s just
> that for ordinary users, they see a lot of warning messages after pressing
> keys, so perhaps it would be better to limit the output. I also agree with
> you that this patch is not necessary—after all, the benefit of this patch is
> indeed limited. If the patch is not merged, I’m fine with that.

If you submit a patch to systemd's 60-keyboard.hwdb introducing the
mapping you will solve this issue for users.

Thanks.

-- 
Dmitry