From aaaa7be2720648b4beafe112e34e7d5127ab4a85 Mon Sep 17 00:00:00 2001 From: hselasky Date: Tue, 4 Feb 2014 09:06:28 +0000 Subject: [PATCH] MFC r261228: When detaching a [USB] keyboard, keys might still be pressed. Ensure that all pressed keys are released before completing the USB keyboard detach. This will prevent so-called "ghost-keys" from appearing after that the USB device generating the key event(s) has been detached. git-svn-id: svn://svn.freebsd.org/base/stable/10@261478 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/dev/usb/input/ukbd.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sys/dev/usb/input/ukbd.c b/sys/dev/usb/input/ukbd.c index dd4b32956..3f3de5188 100644 --- a/sys/dev/usb/input/ukbd.c +++ b/sys/dev/usb/input/ukbd.c @@ -473,7 +473,8 @@ ukbd_get_key(struct ukbd_softc *sc, uint8_t wait) || (sc->sc_flags & UKBD_FLAG_POLLING) != 0, ("not polling in kdb or panic\n")); - if (sc->sc_inputs == 0) { + if (sc->sc_inputs == 0 && + (sc->sc_flags & UKBD_FLAG_GONE) == 0) { /* start transfer, if not already started */ usbd_transfer_start(sc->sc_xfer[UKBD_INTR_DT]); } @@ -1319,6 +1320,18 @@ ukbd_detach(device_t dev) usb_callout_stop(&sc->sc_callout); + /* kill any stuck keys */ + if (sc->sc_flags & UKBD_FLAG_ATTACHED) { + /* stop receiving events from the USB keyboard */ + usbd_transfer_stop(sc->sc_xfer[UKBD_INTR_DT]); + + /* release all leftover keys, if any */ + memset(&sc->sc_ndata, 0, sizeof(sc->sc_ndata)); + + /* process releasing of all keys */ + ukbd_interrupt(sc); + } + ukbd_disable(&sc->sc_kbd); #ifdef KBD_INSTALL_CDEV -- 2.45.0