Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Aug 2009 16:59:55 +0000 (UTC)
From:      Andrew Thompson <thompsa@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r196547 - head/sys/dev/usb
Message-ID:  <200908251659.n7PGxtsq034084@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: thompsa
Date: Tue Aug 25 16:59:55 2009
New Revision: 196547
URL: http://svn.freebsd.org/changeset/base/196547

Log:
  It is possible for all the kthreads to exit (hci modules unloaded) which in
  turn ends our usb process. This means the proc pointer becomes invalid and will
  panic if a new kthread is added. Count the number of threads and clear the proc
  pointer on the last one.
  
  Suggested by:	julian
  MFC after:	3 days

Modified:
  head/sys/dev/usb/usb_process.c

Modified: head/sys/dev/usb/usb_process.c
==============================================================================
--- head/sys/dev/usb/usb_process.c	Tue Aug 25 16:56:33 2009	(r196546)
+++ head/sys/dev/usb/usb_process.c	Tue Aug 25 16:59:55 2009	(r196547)
@@ -64,6 +64,7 @@
 
 #if (__FreeBSD_version >= 800000)
 static struct proc *usbproc;
+static int usb_pcount;
 #define	USB_THREAD_CREATE(f, s, p, ...) \
 		kproc_kthread_add((f), (s), &usbproc, (p), RFHIGHPID, \
 		    0, "usb", __VA_ARGS__)
@@ -183,6 +184,11 @@ usb_process(void *arg)
 	up->up_ptr = NULL;
 	cv_signal(&up->up_cv);
 	mtx_unlock(up->up_mtx);
+#if (__FreeBSD_version >= 800000)
+	/* Clear the proc pointer if this is the last thread. */
+	if (--usb_pcount == 0)
+		usbproc = NULL;
+#endif
 
 	USB_THREAD_EXIT(0);
 }
@@ -218,6 +224,9 @@ usb_proc_create(struct usb_process *up, 
 		up->up_ptr = NULL;
 		goto error;
 	}
+#if (__FreeBSD_version >= 800000)
+	usb_pcount++;
+#endif
 	return (0);
 
 error:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200908251659.n7PGxtsq034084>