Module Name: src
Committed By: maxv
Date: Sat Sep 14 12:41:32 UTC 2019
Modified Files:
src/sys/dev/usb: urio.c
Log Message:
Fix error handling, to prevent kernel crashes when detaching an urio0
device.
Found with vHCI.
To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/dev/usb/urio.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/urio.c
diff -u src/sys/dev/usb/urio.c:1.48 src/sys/dev/usb/urio.c:1.49
--- src/sys/dev/usb/urio.c:1.48 Sun May 5 03:17:54 2019
+++ src/sys/dev/usb/urio.c Sat Sep 14 12:41:32 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: urio.c,v 1.48 2019/05/05 03:17:54 mrg Exp $ */
+/* $NetBSD: urio.c,v 1.49 2019/09/14 12:41:32 maxv Exp $ */
/*
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: urio.c,v 1.48 2019/05/05 03:17:54 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: urio.c,v 1.49 2019/09/14 12:41:32 maxv Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -106,6 +106,10 @@ struct urio_softc {
device_t sc_dev;
struct usbd_device * sc_udev;
struct usbd_interface * sc_iface;
+ enum {
+ URIO_INIT_NONE,
+ URIO_INIT_INITED
+ } sc_init_state;
int sc_in_addr;
struct usbd_pipe * sc_in_pipe;
@@ -163,6 +167,7 @@ urio_attach(device_t parent, device_t se
DPRINTFN(10,("urio_attach: sc=%p\n", sc));
sc->sc_dev = self;
+ sc->sc_init_state = URIO_INIT_NONE;
aprint_naive("\n");
aprint_normal("\n");
@@ -215,6 +220,8 @@ urio_attach(device_t parent, device_t se
usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev);
+ sc->sc_init_state = URIO_INIT_INITED;
+
return;
}
@@ -254,6 +261,9 @@ urio_detach(device_t self, int flags)
mn = device_unit(self);
vdevgone(maj, mn, mn, VCHR);
+ if (sc->sc_init_state < URIO_INIT_INITED)
+ return 0;
+
usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
return 0;