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 (ld...@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;
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to