Module Name: src Committed By: martin Date: Thu Jan 12 12:09:18 UTC 2023
Modified Files: src/sys/dev/usb [netbsd-10]: ukbd.c Log Message: Pull up following revision(s) (requested by mrg in ticket #43): sys/dev/usb/ukbd.c: revision 1.162 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. To generate a diff of this commit: cvs rdiff -u -r1.161 -r1.161.4.1 src/sys/dev/usb/ukbd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/usb/ukbd.c diff -u src/sys/dev/usb/ukbd.c:1.161 src/sys/dev/usb/ukbd.c:1.161.4.1 --- src/sys/dev/usb/ukbd.c:1.161 Wed Apr 6 21:51:29 2022 +++ src/sys/dev/usb/ukbd.c Thu Jan 12 12:09:18 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: ukbd.c,v 1.161 2022/04/06 21:51:29 mlelstv Exp $ */ +/* $NetBSD: ukbd.c,v 1.161.4.1 2023/01/12 12:09:18 martin 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.161.4.1 2023/01/12 12:09:18 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -294,7 +294,8 @@ struct ukbd_softc { 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 @@ ukbd_attach(device_t parent, device_t se sc->sc_wskbddev = config_found(self, &a, wskbddevprint, CFARGS_NONE); + sc->sc_attached = true; + return; } @@ -567,7 +570,7 @@ ukbd_activate(device_t self, enum devact switch (act) { case DVACT_DEACTIVATE: - sc->sc_dying = 1; + sc->sc_dying = true; return 0; default: return EOPNOTSUPP; @@ -584,6 +587,9 @@ ukbd_detach(device_t self, int flags) pmf_device_deregister(self); + if (!sc->sc_attached) + return rv; + if (sc->sc_console_keyboard) { /* * Disconnect our consops and set ukbd_is_console