Skip to content

Commit

Permalink
Fix dumpkeys with keycode 0
Browse files Browse the repository at this point in the history
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: bdf5742 ("libkeymap: dump action codes for keycode 0")
Signed-off-by: Alexey Gladkov <legion@kernel.org>
  • Loading branch information
legionus committed Dec 16, 2024
1 parent cf9b00c commit b1c5991
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 40 deletions.
15 changes: 13 additions & 2 deletions src/libkeymap/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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++) {
Expand Down
28 changes: 0 additions & 28 deletions tests/data/dumpkeys-fulltable/mac-qwerty-layout.map

This file was deleted.

1 change: 0 additions & 1 deletion tests/data/dumpkeys-fulltable/ruwin_cplk-UTF-8.map
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 0 additions & 9 deletions tests/libkeymap.at
Original file line number Diff line number Diff line change
Expand Up @@ -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" ])
Expand Down

0 comments on commit b1c5991

Please sign in to comment.