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

Modified Files:
        src/sys/dev/usb: if_athn_usb.c if_athn_usb.h

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

Found with vHCI.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/dev/usb/if_athn_usb.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/usb/if_athn_usb.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_athn_usb.c
diff -u src/sys/dev/usb/if_athn_usb.c:1.34 src/sys/dev/usb/if_athn_usb.c:1.35
--- src/sys/dev/usb/if_athn_usb.c:1.34	Mon Jun  3 09:58:31 2019
+++ src/sys/dev/usb/if_athn_usb.c	Sat Sep 14 12:36:35 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_athn_usb.c,v 1.34 2019/06/03 09:58:31 msaitoh Exp $	*/
+/*	$NetBSD: if_athn_usb.c,v 1.35 2019/09/14 12:36:35 maxv Exp $	*/
 /*	$OpenBSD: if_athn_usb.c,v 1.12 2013/01/14 09:50:31 jsing Exp $	*/
 
 /*-
@@ -22,7 +22,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_athn_usb.c,v 1.34 2019/06/03 09:58:31 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_athn_usb.c,v 1.35 2019/09/14 12:36:35 maxv Exp $");
 
 #ifdef	_KERNEL_OPT
 #include "opt_inet.h"
@@ -260,6 +260,7 @@ athn_usb_attach(device_t parent, device_
 
 	DPRINTFN(DBG_FN, sc, "\n");
 
+	usc->usc_init_state = ATHN_INIT_NONE;
 	usc->usc_athn_attached = 0;
 	usc->usc_flags = athn_usb_lookup(uaa->uaa_vendor, uaa->uaa_product)->flags;
 	sc->sc_flags |= ATHN_FLAG_USB;
@@ -328,6 +329,8 @@ athn_usb_attach(device_t parent, device_
 	if (!pmf_device_register(self, NULL, NULL))
 		aprint_error_dev(self, "couldn't establish power handler\n");
 
+	usc->usc_init_state = ATHN_INIT_INITED;
+
 	return;
 
  fail:
@@ -478,6 +481,9 @@ athn_usb_detach(device_t self, int flags
 
 	DPRINTFN(DBG_FN, usc, "\n");
 
+	if (usc->usc_init_state < ATHN_INIT_INITED)
+		return 0;
+
 	pmf_device_deregister(self);
 
 	mutex_enter(&usc->usc_lock);

Index: src/sys/dev/usb/if_athn_usb.h
diff -u src/sys/dev/usb/if_athn_usb.h:1.5 src/sys/dev/usb/if_athn_usb.h:1.6
--- src/sys/dev/usb/if_athn_usb.h:1.5	Sat Jan 21 12:45:22 2017
+++ src/sys/dev/usb/if_athn_usb.h	Sat Sep 14 12:36:35 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_athn_usb.h,v 1.5 2017/01/21 12:45:22 skrll Exp $	*/
+/*	$NetBSD: if_athn_usb.h,v 1.6 2019/09/14 12:36:35 maxv Exp $	*/
 /*	$OpenBSD: if_athn_usb.h,v 1.3 2012/11/10 14:35:06 mikeb Exp $	*/
 
 /*-
@@ -441,6 +441,10 @@ struct athn_usb_softc {
 	struct athn_softc		usc_sc;
 #define usc_dev		usc_sc.sc_dev
 
+	enum {
+		ATHN_INIT_NONE,
+		ATHN_INIT_INITED
+	} usc_init_state;
 	int				usc_athn_attached;
 
 	kmutex_t			usc_lock;

Reply via email to