Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Apr 2015 16:22:06 +0000 (UTC)
From:      Neel Natu <neel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r281559 - head/sys/kern
Message-ID:  <201504151622.t3FGM6ef057150@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: neel
Date: Wed Apr 15 16:22:05 2015
New Revision: 281559
URL: https://svnweb.freebsd.org/changeset/base/281559

Log:
  Fix handling of BUS_PROBE_NOWILDCARD in 'device_probe_child()'.
  
  Device probe value of BUS_PROBE_NOWILDCARD should be treated specially only
  if the device has a fixed devclass. Otherwise it should be interpreted just
  as if the driver doesn't want to claim the device.
  
  Prior to this change a device that was not claimed explicitly by its driver
  would remain "attached" to the driver that returned BUS_PROBE_NOWILDCARD.
  This would bump up the reference on 'driver->refs' and its 'dev->ops' would
  point to the 'driver->ops'. When the driver is subsequently unloaded the
  'dev->ops->cls' is left pointing to freed memory.
  
  This fixes an easily reproducible #GP fault caused by loading and unloading
  vmm.ko multiple times.
  
  Differential Revision:	https://reviews.freebsd.org/D2294
  Reviewed by:	imp, jhb
  Discussed with:	rstone
  Reported by:	Leon Dang (ldang@nahannisys.com)
  MFC after:	2 weeks

Modified:
  head/sys/kern/subr_bus.c

Modified: head/sys/kern/subr_bus.c
==============================================================================
--- head/sys/kern/subr_bus.c	Wed Apr 15 14:46:45 2015	(r281558)
+++ head/sys/kern/subr_bus.c	Wed Apr 15 16:22:05 2015	(r281559)
@@ -2113,6 +2113,16 @@ device_probe_child(device_t dev, device_
 			}
 
 			/*
+			 * Probes that return BUS_PROBE_NOWILDCARD or lower
+			 * only match on devices whose driver was explicitly
+			 * specified.
+			 */
+			if (result <= BUS_PROBE_NOWILDCARD &&
+			    !(child->flags & DF_FIXEDCLASS)) {
+				result = ENXIO;
+			}
+
+			/*
 			 * The driver returned an error so it
 			 * certainly doesn't match.
 			 */
@@ -2127,14 +2137,6 @@ device_probe_child(device_t dev, device_
 			 * of pri for the first match.
 			 */
 			if (best == NULL || result > pri) {
-				/*
-				 * Probes that return BUS_PROBE_NOWILDCARD
-				 * or lower only match on devices whose
-				 * driver was explicitly specified.
-				 */
-				if (result <= BUS_PROBE_NOWILDCARD &&
-				    !(child->flags & DF_FIXEDCLASS))
-					continue;
 				best = dl;
 				pri = result;
 				continue;



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