From b1c599197153f89df68bebe06f8be1ac9b6e7437 Mon Sep 17 00:00:00 2001 From: Alexey Gladkov Date: Mon, 16 Dec 2024 17:23:39 +0100 Subject: [PATCH] Fix dumpkeys with keycode 0 The value of keycode 0 has a special meaning, but on some architectures (like powerpc) keyboards may generate keycode zero. In other cases, kernel places K_ALLOCATED there. Since it depends on the architecture you need to revert the test added earlier. Unfortunately the opposite is also true. On some architectures (where it is possible to specify keycode 0) tests will fail. It's lucky there aren't many architectures like this. Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/tty/vt/keyboard.c#n1968 Fixes: bdf5742c ("libkeymap: dump action codes for keycode 0") Signed-off-by: Alexey Gladkov --- src/libkeymap/dump.c | 15 ++++++++-- .../dumpkeys-fulltable/mac-qwerty-layout.map | 28 ------------------- .../dumpkeys-fulltable/ruwin_cplk-UTF-8.map | 1 - tests/libkeymap.at | 9 ------ 4 files changed, 13 insertions(+), 40 deletions(-) delete mode 100644 tests/data/dumpkeys-fulltable/mac-qwerty-layout.map diff --git a/src/libkeymap/dump.c b/src/libkeymap/dump.c index 6af39dc5..7daa7095 100644 --- a/src/libkeymap/dump.c +++ b/src/libkeymap/dump.c @@ -24,6 +24,17 @@ #define U(x) ((x) ^ 0xf000) +/* + * ++Geert: non-PC keyboards may generate keycode zero + * + * See https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/tty/vt/keyboard.c#n1968 + */ +#if !defined(__mc68000__) && !defined(__powerpc__) +# define MIN_KEYCODE 1 +#else +# define MIN_KEYCODE 0 +#endif + static void outchar(FILE *fd, unsigned int c, int comma) { @@ -427,7 +438,7 @@ void lk_dump_keys(struct lk_ctx *ctx, FILE *fd, lk_table_shape table, char numer if (!(j != ja && lk_map_exists(ctx, j) && lk_map_exists(ctx, ja))) continue; - for (i = 0; i < NR_KEYS; i++) { + for (i = MIN_KEYCODE; i < NR_KEYS; i++) { int buf0, buf1, type; buf0 = lk_get_key(ctx, j, i); @@ -453,7 +464,7 @@ void lk_dump_keys(struct lk_ctx *ctx, FILE *fd, lk_table_shape table, char numer not_alt_is_meta: no_shorthands: - for (i = 0; i < NR_KEYS; i++) { + for (i = MIN_KEYCODE; i < NR_KEYS; i++) { all_holes = 1; for (j = 0; j < keymapnr; j++) { diff --git a/tests/data/dumpkeys-fulltable/mac-qwerty-layout.map b/tests/data/dumpkeys-fulltable/mac-qwerty-layout.map deleted file mode 100644 index 8313b0cd..00000000 --- a/tests/data/dumpkeys-fulltable/mac-qwerty-layout.map +++ /dev/null @@ -1,28 +0,0 @@ -keymaps 0 -alt_is_meta -keycode 0 = a -keycode 1 = s -keycode 2 = d -keycode 3 = f -keycode 4 = h -keycode 5 = g -keycode 6 = z -keycode 7 = x -keycode 8 = c -keycode 9 = v -keycode 11 = b -keycode 12 = q -keycode 13 = w -keycode 14 = e -keycode 15 = r -keycode 16 = y -keycode 17 = t -keycode 31 = o -keycode 32 = u -keycode 34 = i -keycode 35 = p -keycode 37 = l -keycode 38 = j -keycode 40 = k -keycode 45 = n -keycode 46 = m diff --git a/tests/data/dumpkeys-fulltable/ruwin_cplk-UTF-8.map b/tests/data/dumpkeys-fulltable/ruwin_cplk-UTF-8.map index 625b76a8..80c66726 100644 --- a/tests/data/dumpkeys-fulltable/ruwin_cplk-UTF-8.map +++ b/tests/data/dumpkeys-fulltable/ruwin_cplk-UTF-8.map @@ -1,5 +1,4 @@ keymaps 0-255 -keycode 0 = 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 keycode 1 = 0x001b 0x001b 0x001b 0x001b 0x0200 0x0200 0x0200 0x0200 0x081b 0x0200 0x081b 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 keycode 2 = 0x0031 0x0021 0x0031 0x0021 0x0200 0x0200 0x0200 0x0200 0x0831 0x0821 0x0831 0x0821 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 keycode 3 = 0x0032 0x0040 0x0032 0x0022 0x0000 0x0200 0x0000 0x0200 0x0832 0x0840 0x0832 0x0840 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 0x0200 diff --git a/tests/libkeymap.at b/tests/libkeymap.at index a7f8cccd..929d1ccc 100644 --- a/tests/libkeymap.at +++ b/tests/libkeymap.at @@ -147,15 +147,6 @@ AT_CHECK([$abs_builddir/helpers/libkeymap-dumpkeys $abs_srcdir/data/dumpkeys-ful [0], [expout]) AT_CLEANUP -AT_SETUP([test 25 (keycode 0)]) -AT_KEYWORDS([libkeymap unittest]) -cp -f -- \ - "$abs_srcdir/data/dumpkeys-fulltable/mac-qwerty-layout.map" \ - expout -AT_CHECK([$abs_builddir/helpers/libkeymap-dumpkeys $abs_srcdir/data/dumpkeys-fulltable/mac-qwerty-layout.map DEFAULT FALSE], - [0], [expout]) -AT_CLEANUP - AT_SETUP([binary keymap (us.map)]) AT_KEYWORDS([libkeymap unittest]) AT_SKIP_IF([ test "$(arch)" != "x86_64" ])