Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb ukbd(4): remember how much of attach worked so d...



details:   https://anonhg.NetBSD.org/src/rev/b00efe427e9b
branches:  trunk
changeset: 372986:b00efe427e9b
user:      mrg <mrg%NetBSD.org@localhost>
date:      Tue Jan 10 18:20:10 2023 +0000

description:
ukbd(4): remember how much of attach worked so detach works.

if ukbd_attach() fails it means it has only really done the pmf
setup, nothing else, so avoid trying to remove callouts, child
devices, or console setup, usb task and uhidev operations.

fixes the crash (but not the underlying ukbd doesn't work issue)
seen in PR#57149.

diffstat:

 sys/dev/usb/ukbd.c |  14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diffs (56 lines):

diff -r c0b660c4cf6a -r b00efe427e9b sys/dev/usb/ukbd.c
--- a/sys/dev/usb/ukbd.c        Tue Jan 10 00:05:53 2023 +0000
+++ b/sys/dev/usb/ukbd.c        Tue Jan 10 18:20:10 2023 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: ukbd.c,v 1.161 2022/04/06 21:51:29 mlelstv Exp $        */
+/*      $NetBSD: ukbd.c,v 1.162 2023/01/10 18:20:10 mrg Exp $        */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.161 2022/04/06 21:51:29 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.162 2023/01/10 18:20:10 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -294,7 +294,8 @@
        int sc_npollchar;
        uint16_t sc_pollchars[MAXKEYS];
 
-       u_char sc_dying;
+       bool sc_dying;
+       bool sc_attached;
 };
 
 #ifdef UKBD_DEBUG
@@ -520,6 +521,8 @@
 
        sc->sc_wskbddev = config_found(self, &a, wskbddevprint, CFARGS_NONE);
 
+       sc->sc_attached = true;
+
        return;
 }
 
@@ -567,7 +570,7 @@
 
        switch (act) {
        case DVACT_DEACTIVATE:
-               sc->sc_dying = 1;
+               sc->sc_dying = true;
                return 0;
        default:
                return EOPNOTSUPP;
@@ -584,6 +587,9 @@
 
        pmf_device_deregister(self);
 
+       if (!sc->sc_attached)
+               return rv;
+
        if (sc->sc_console_keyboard) {
                /*
                 * Disconnect our consops and set ukbd_is_console



Home | Main Index | Thread Index | Old Index