Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb Fix error handling, to prevent kernel crashes wh...



details:   https://anonhg.NetBSD.org/src/rev/c36cf1bcab86
branches:  trunk
changeset: 459509:c36cf1bcab86
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Sep 14 12:41:32 2019 +0000

description:
Fix error handling, to prevent kernel crashes when detaching an urio0
device.

Found with vHCI.

diffstat:

 sys/dev/usb/urio.c |  14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diffs (56 lines):

diff -r c202f5171a21 -r c36cf1bcab86 sys/dev/usb/urio.c
--- a/sys/dev/usb/urio.c        Sat Sep 14 12:40:31 2019 +0000
+++ b/sys/dev/usb/urio.c        Sat Sep 14 12:41:32 2019 +0000
@@ -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 @@
        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 @@
        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 @@
 
        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 @@
        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;



Home | Main Index | Thread Index | Old Index