On Fri, Feb 16, 2024 at 05:51:43PM +0000, Miod Vallat wrote:
> > > Do you have machdep.forceukbd=1 somewhere in /etc/sysctl.conf?
> > 
> > Ah, yes! And there's no USB keyboard now, I added that when the
> > disk was in a real machine before I moved it to a VM.
> 
> Ok, so this is what causes the keymap pointer to be reset to NULL. Phew!
> Root cause found.
> 
> Anton, could you tweak your diff so that it becomes something like
> 
>       count = 0;
>       if (sc->id->t_keymap.keydesc)
>               for (; sc->id->t_keymap.keydesc[count].name; count ++)
>                       ...
> 
> in order to only check for a NULL pointer once?

diff --git sys/dev/wscons/wskbd.c sys/dev/wscons/wskbd.c
index 7631cd5f701..5708d628242 100644
--- sys/dev/wscons/wskbd.c
+++ sys/dev/wscons/wskbd.c
@@ -1229,8 +1229,11 @@ getkeyrepeat:
 
        case WSKBDIO_GETENCODINGS:
                uedp = (struct wskbd_encoding_data *)data;
-               for (count = 0; sc->id->t_keymap.keydesc[count].name; count++)
-                       ;
+               count = 0;
+               if (sc->id->t_keymap.keydesc != NULL) {
+                       while (sc->id->t_keymap.keydesc[count].name)
+                               count++;
+               }
                if (uedp->nencodings > count)
                        uedp->nencodings = count;
                for (i = 0; i < uedp->nencodings; i++) {

Reply via email to