Module Name:    src
Committed By:   maxv
Date:           Sat Sep 14 12:42:36 UTC 2019

Modified Files:
        src/sys/dev/usb: if_ural.c if_uralvar.h

Log Message:
Fix error handling, to prevent kernel crashes when detaching an ural0
device.

Found with vHCI.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/dev/usb/if_ural.c
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/usb/if_uralvar.h

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/if_ural.c
diff -u src/sys/dev/usb/if_ural.c:1.59 src/sys/dev/usb/if_ural.c:1.60
--- src/sys/dev/usb/if_ural.c:1.59	Sun May  5 03:17:54 2019
+++ src/sys/dev/usb/if_ural.c	Sat Sep 14 12:42:36 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ural.c,v 1.59 2019/05/05 03:17:54 mrg Exp $ */
+/*	$NetBSD: if_ural.c,v 1.60 2019/09/14 12:42:36 maxv Exp $ */
 /*	$FreeBSD: /repoman/r/ncvs/src/sys/dev/usb/if_ural.c,v 1.40 2006/06/02 23:14:40 sam Exp $	*/
 
 /*-
@@ -24,7 +24,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ural.c,v 1.59 2019/05/05 03:17:54 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ural.c,v 1.60 2019/09/14 12:42:36 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -367,6 +367,7 @@ ural_attach(device_t parent, device_t se
 
 	sc->sc_dev = self;
 	sc->sc_udev = uaa->uaa_device;
+	sc->sc_init_state = URAL_INIT_NONE;
 
 	aprint_naive("\n");
 	aprint_normal("\n");
@@ -513,6 +514,8 @@ ural_attach(device_t parent, device_t se
 
 	ieee80211_announce(ic);
 
+	sc->sc_init_state = URAL_INIT_INITED;
+
 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev);
 
 	if (!pmf_device_register(self, NULL, NULL))
@@ -529,6 +532,9 @@ ural_detach(device_t self, int flags)
 	struct ifnet *ifp = &sc->sc_if;
 	int s;
 
+	if (sc->sc_init_state < URAL_INIT_INITED)
+		return 0;
+
 	pmf_device_deregister(self);
 
 	s = splusb();

Index: src/sys/dev/usb/if_uralvar.h
diff -u src/sys/dev/usb/if_uralvar.h:1.12 src/sys/dev/usb/if_uralvar.h:1.13
--- src/sys/dev/usb/if_uralvar.h:1.12	Sat Apr 23 10:15:31 2016
+++ src/sys/dev/usb/if_uralvar.h	Sat Sep 14 12:42:36 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_uralvar.h,v 1.12 2016/04/23 10:15:31 skrll Exp $ */
+/*	$NetBSD: if_uralvar.h,v 1.13 2019/09/14 12:42:36 maxv Exp $ */
 /*	$OpenBSD: if_ralvar.h,v 1.2 2005/05/13 18:42:50 damien Exp $  */
 
 /*-
@@ -74,6 +74,11 @@ struct ural_softc {
 	device_t		sc_dev;
 	struct ethercom		sc_ec;
 #define sc_if	sc_ec.ec_if
+
+	enum {
+		URAL_INIT_NONE,
+		URAL_INIT_INITED
+	} sc_init_state;
 	struct ieee80211com	sc_ic;
 	int			(*sc_newstate)(struct ieee80211com *,
 				    enum ieee80211_state, int);

Reply via email to