diff options
| author | maxv <maxv@NetBSD.org> | 2019-09-14 12:53:24 +0000 |
|---|---|---|
| committer | maxv <maxv@NetBSD.org> | 2019-09-14 12:53:24 +0000 |
| commit | e323b4d895cfcb7d1d4141e5e19dd7fb104c3b8d (patch) | |
| tree | 3180b6be650c22d43b8df5a98aa33e23b07ebfbd /sys/dev/usb | |
| parent | fbc7cccea87e3a91df69cdd0a62c474aa508ca7e (diff) | |
Fix error handling, to prevent kernel crashes when detaching an upgt0
device.
Found with vHCI.
Diffstat (limited to 'sys/dev/usb')
| -rw-r--r-- | sys/dev/usb/if_upgt.c | 9 | ||||
| -rw-r--r-- | sys/dev/usb/if_upgtvar.h | 6 |
2 files changed, 12 insertions, 3 deletions
diff --git a/sys/dev/usb/if_upgt.c b/sys/dev/usb/if_upgt.c index 40958633d63..0b30c1e38f1 100644 --- a/sys/dev/usb/if_upgt.c +++ b/sys/dev/usb/if_upgt.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_upgt.c,v 1.25 2019/03/06 08:08:25 msaitoh Exp $ */ +/* $NetBSD: if_upgt.c,v 1.26 2019/09/14 12:53:24 maxv Exp $ */ /* $OpenBSD: if_upgt.c,v 1.49 2010/04/20 22:05:43 tedu Exp $ */ /* @@ -18,7 +18,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_upgt.c,v 1.25 2019/03/06 08:08:25 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_upgt.c,v 1.26 2019/09/14 12:53:24 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_usb.h" @@ -239,6 +239,7 @@ upgt_attach(device_t parent, device_t self, void *aux) */ sc->sc_dev = self; sc->sc_udev = uaa->uaa_device; + sc->sc_init_state = UPGT_INIT_NONE; devinfop = usbd_devinfo_alloc(sc->sc_udev, 0); aprint_normal_dev(sc->sc_dev, "%s\n", devinfop); @@ -306,6 +307,7 @@ upgt_attach(device_t parent, device_t self, void *aux) callout_setfunc(&sc->scan_to, upgt_next_scan, sc); callout_init(&sc->led_to, 0); callout_setfunc(&sc->led_to, upgt_set_led_blink, sc); + sc->sc_init_state = UPGT_INIT_INITED; /* * Open TX and RX USB bulk pipes. @@ -498,6 +500,9 @@ upgt_detach(device_t self, int flags) DPRINTF(1, "%s: %s\n", device_xname(sc->sc_dev), __func__); + if (sc->sc_init_state < UPGT_INIT_INITED) + return 0; + s = splnet(); if (ifp->if_flags & IFF_RUNNING) diff --git a/sys/dev/usb/if_upgtvar.h b/sys/dev/usb/if_upgtvar.h index a5eb2ff7640..ae0732244f1 100644 --- a/sys/dev/usb/if_upgtvar.h +++ b/sys/dev/usb/if_upgtvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: if_upgtvar.h,v 1.2 2016/04/23 10:15:31 skrll Exp $ */ +/* $NetBSD: if_upgtvar.h,v 1.3 2019/09/14 12:53:24 maxv Exp $ */ /* $OpenBSD: if_upgtvar.h,v 1.15 2009/08/10 20:02:19 deraadt Exp $ */ /* @@ -398,6 +398,10 @@ struct upgt_softc { struct ethercom sc_ec; #define sc_if sc_ec.ec_if + enum { + UPGT_INIT_NONE, + UPGT_INIT_INITED + } sc_init_state; struct usbd_device * sc_udev; struct usbd_interface * sc_iface; int sc_rx_no; |
