diff --git a/sys/dev/kbd/kbd.c b/sys/dev/kbd/kbd.c --- a/sys/dev/kbd/kbd.c +++ b/sys/dev/kbd/kbd.c @@ -35,7 +35,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -97,13 +99,11 @@ { keyboard_t **new_kbd; int newsize; - int s; - s = spltty(); + GIANT_REQUIRED; newsize = rounddown(keyboards + ARRAY_DELTA, ARRAY_DELTA); new_kbd = malloc(sizeof(*new_kbd)*newsize, M_DEVBUF, M_NOWAIT|M_ZERO); if (new_kbd == NULL) { - splx(s); return (ENOMEM); } bcopy(keyboard, new_kbd, sizeof(*keyboard)*keyboards); @@ -111,7 +111,6 @@ free(keyboard, M_DEVBUF); keyboard = new_kbd; keyboards = newsize; - splx(s); if (bootverbose) printf("kbd: new array size %d\n", keyboards); @@ -245,30 +244,26 @@ kbd_unregister(keyboard_t *kbd) { int error; - int s; + GIANT_REQUIRED; if ((kbd->kb_index < 0) || (kbd->kb_index >= keyboards)) return (ENOENT); if (keyboard[kbd->kb_index] != kbd) return (ENOENT); - s = spltty(); if (KBD_IS_BUSY(kbd)) { error = (*kbd->kb_callback.kc_func)(kbd, KBDIO_UNLOADING, kbd->kb_callback.kc_arg); if (error) { - splx(s); return (error); } if (KBD_IS_BUSY(kbd)) { - splx(s); return (EBUSY); } } KBD_INVALID(kbd); keyboard[kbd->kb_index] = NULL; - splx(s); return (0); } @@ -333,16 +328,14 @@ void *arg) { int index; - int s; + GIANT_REQUIRED; if (func == NULL) return (-1); - s = spltty(); index = kbd_find_keyboard(driver, unit); if (index >= 0) { if (KBD_IS_BUSY(keyboard[index])) { - splx(s); return (-1); } keyboard[index]->kb_token = id; @@ -351,7 +344,6 @@ keyboard[index]->kb_callback.kc_arg = arg; kbdd_clear_state(keyboard[index]); } - splx(s); return (index); } @@ -359,9 +351,8 @@ kbd_release(keyboard_t *kbd, void *id) { int error; - int s; - s = spltty(); + GIANT_REQUIRED; if (!KBD_IS_VALID(kbd) || !KBD_IS_BUSY(kbd)) { error = EINVAL; } else if (kbd->kb_token != id) { @@ -374,7 +365,6 @@ kbdd_clear_state(kbd); error = 0; } - splx(s); return (error); } @@ -383,9 +373,8 @@ void *arg) { int error; - int s; - s = spltty(); + GIANT_REQUIRED; if (!KBD_IS_VALID(kbd) || !KBD_IS_BUSY(kbd)) { error = EINVAL; } else if (kbd->kb_token != id) { @@ -397,7 +386,6 @@ kbd->kb_callback.kc_arg = arg; error = 0; } - splx(s); return (error); } @@ -542,20 +530,17 @@ { keyboard_t *kbd; genkbd_softc_t *sc; - int s; int i; - s = spltty(); + GIANT_REQUIRED; sc = dev->si_drv1; kbd = kbd_get_keyboard(KBD_INDEX(dev)); if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) { - splx(s); return (ENXIO); } i = kbd_allocate(kbd->kb_name, kbd->kb_unit, sc, genkbd_event, (void *)sc); if (i < 0) { - splx(s); return (EBUSY); } /* assert(i == kbd->kb_index) */ @@ -567,7 +552,6 @@ */ sc->gkb_q_length = 0; - splx(s); return (0); } @@ -577,13 +561,12 @@ { keyboard_t *kbd; genkbd_softc_t *sc; - int s; + GIANT_REQUIRED; /* * NOTE: the device may have already become invalid. * kbd == NULL || !KBD_IS_VALID(kbd) */ - s = spltty(); sc = dev->si_drv1; kbd = kbd_get_keyboard(KBD_INDEX(dev)); if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) { @@ -591,7 +574,6 @@ } else { kbd_release(kbd, (void *)sc); } - splx(s); return (0); } @@ -603,35 +585,29 @@ u_char buffer[KB_BUFSIZE]; int len; int error; - int s; + GIANT_REQUIRED; /* wait for input */ - s = spltty(); sc = dev->si_drv1; kbd = kbd_get_keyboard(KBD_INDEX(dev)); if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) { - splx(s); return (ENXIO); } while (sc->gkb_q_length == 0) { if (flag & O_NONBLOCK) { - splx(s); return (EWOULDBLOCK); } sc->gkb_flags |= KB_ASLEEP; error = tsleep(sc, PZERO | PCATCH, "kbdrea", 0); kbd = kbd_get_keyboard(KBD_INDEX(dev)); if ((kbd == NULL) || !KBD_IS_VALID(kbd)) { - splx(s); return (ENXIO); /* our keyboard has gone... */ } if (error) { sc->gkb_flags &= ~KB_ASLEEP; - splx(s); return (error); } } - splx(s); /* copy as much input as possible */ error = 0; @@ -680,10 +656,9 @@ keyboard_t *kbd; genkbd_softc_t *sc; int revents; - int s; + GIANT_REQUIRED; revents = 0; - s = spltty(); sc = dev->si_drv1; kbd = kbd_get_keyboard(KBD_INDEX(dev)); if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) { @@ -694,7 +669,6 @@ else selrecord(td, &sc->gkb_rsel); } - splx(s); return (revents); } @@ -818,11 +792,10 @@ okeymap_t *omapp; keyarg_t *keyp; fkeyarg_t *fkeyp; - int s; int i, j; int error; - s = spltty(); + GIANT_REQUIRED; switch (cmd) { case KDGKBINFO: /* get keyboard information */ @@ -848,7 +821,6 @@ case GIO_KEYMAP: /* get keyboard translation table */ error = copyout(kbd->kb_keymap, *(void **)arg, sizeof(keymap_t)); - splx(s); return (error); case OGIO_KEYMAP: /* get keyboard translation table (compat) */ mapp = kbd->kb_keymap; @@ -879,7 +851,6 @@ } else { error = copyin(*(void **)arg, mapp, sizeof *mapp); if (error != 0) { - splx(s); free(mapp, M_TEMP); return (error); } @@ -887,7 +858,6 @@ error = keymap_change_ok(kbd->kb_keymap, mapp, curthread); if (error != 0) { - splx(s); free(mapp, M_TEMP); return (error); } @@ -896,7 +866,6 @@ free(mapp, M_TEMP); break; #else - splx(s); return (ENODEV); #endif @@ -904,7 +873,6 @@ keyp = (keyarg_t *)arg; if (keyp->keynum >= sizeof(kbd->kb_keymap->key) / sizeof(kbd->kb_keymap->key[0])) { - splx(s); return (EINVAL); } bcopy(&kbd->kb_keymap->key[keyp->keynum], &keyp->key, @@ -915,20 +883,17 @@ keyp = (keyarg_t *)arg; if (keyp->keynum >= sizeof(kbd->kb_keymap->key) / sizeof(kbd->kb_keymap->key[0])) { - splx(s); return (EINVAL); } error = key_change_ok(&kbd->kb_keymap->key[keyp->keynum], &keyp->key, curthread); if (error != 0) { - splx(s); return (error); } bcopy(&keyp->key, &kbd->kb_keymap->key[keyp->keynum], sizeof(keyp->key)); break; #else - splx(s); return (ENODEV); #endif @@ -940,20 +905,17 @@ error = accent_change_ok(kbd->kb_accentmap, (accentmap_t *)arg, curthread); if (error != 0) { - splx(s); return (error); } bcopy(arg, kbd->kb_accentmap, sizeof(*kbd->kb_accentmap)); break; #else - splx(s); return (ENODEV); #endif case GETFKEY: /* get functionkey string */ fkeyp = (fkeyarg_t *)arg; if (fkeyp->keynum >= kbd->kb_fkeytab_size) { - splx(s); return (EINVAL); } bcopy(kbd->kb_fkeytab[fkeyp->keynum].str, fkeyp->keydef, @@ -964,13 +926,11 @@ #ifndef KBD_DISABLE_KEYMAP_LOAD fkeyp = (fkeyarg_t *)arg; if (fkeyp->keynum >= kbd->kb_fkeytab_size) { - splx(s); return (EINVAL); } error = fkey_change_ok(&kbd->kb_fkeytab[fkeyp->keynum], fkeyp, curthread); if (error != 0) { - splx(s); return (error); } kbd->kb_fkeytab[fkeyp->keynum].len = min(fkeyp->flen, MAXFK); @@ -978,16 +938,13 @@ kbd->kb_fkeytab[fkeyp->keynum].len); break; #else - splx(s); return (ENODEV); #endif default: - splx(s); return (ENOIOCTL); } - splx(s); return (0); }