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 at...



details:   https://anonhg.NetBSD.org/src/rev/dcd2360681be
branches:  trunk
changeset: 459522:dcd2360681be
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Sep 14 15:21:19 2019 +0000

description:
Fix error handling, to prevent kernel crashes at detach time. Found by
vHCI.

diffstat:

 sys/dev/usb/ustir.c |  20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diffs (62 lines):

diff -r ea003a880f56 -r dcd2360681be sys/dev/usb/ustir.c
--- a/sys/dev/usb/ustir.c       Sat Sep 14 15:19:52 2019 +0000
+++ b/sys/dev/usb/ustir.c       Sat Sep 14 15:21:19 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ustir.c,v 1.40 2019/05/05 03:17:54 mrg Exp $   */
+/*     $NetBSD: ustir.c,v 1.41 2019/09/14 15:21:19 maxv Exp $  */
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ustir.c,v 1.40 2019/05/05 03:17:54 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ustir.c,v 1.41 2019/09/14 15:21:19 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -96,6 +96,10 @@
        device_t                sc_dev;
        struct usbd_device      *sc_udev;
        struct usbd_interface   *sc_iface;
+       enum {
+               USTIR_INIT_NONE,
+               USTIR_INIT_INITED
+       } sc_init_state;
 
        uint8_t                 *sc_ur_buf; /* Unencapsulated frame */
        u_int                   sc_ur_framelen;
@@ -250,6 +254,7 @@
        DPRINTFN(10,("ustir_attach: sc=%p\n", sc));
 
        sc->sc_dev = self;
+       sc->sc_init_state = USTIR_INIT_NONE;
 
        aprint_naive("\n");
        aprint_normal("\n");
@@ -302,6 +307,7 @@
        sc->sc_child = config_found(self, &ia, ir_print);
        selinit(&sc->sc_rd_sel);
        selinit(&sc->sc_wr_sel);
+       sc->sc_init_state = USTIR_INIT_INITED;
 
        return;
 }
@@ -369,10 +375,12 @@
        if (sc->sc_child != NULL)
                rv = config_detach(sc->sc_child, flags);
 
-       usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
-
-       seldestroy(&sc->sc_rd_sel);
-       seldestroy(&sc->sc_wr_sel);
+       if (sc->sc_init_state >= USTIR_INIT_INITED) {
+               usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
+                   sc->sc_dev);
+               seldestroy(&sc->sc_rd_sel);
+               seldestroy(&sc->sc_wr_sel);
+       }
 
        return rv;
 }



Home | Main Index | Thread Index | Old Index