diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -2074,6 +2074,7 @@ driverlink_t best = NULL; driverlink_t dl; int result, pri = 0; + /* We should preserve the devclass (or lack of) set by the bus. */ int hasclass = (child->devclass != NULL); GIANT_REQUIRED; @@ -2125,11 +2126,6 @@ result = DEVICE_PROBE(child); - /* Reset flags and devclass before the next probe. */ - child->devflags = 0; - if (!hasclass) - (void)device_set_devclass(child, NULL); - /* * If the driver returns SUCCESS, there can be * no higher match for this device. @@ -2140,6 +2136,11 @@ break; } + /* Reset flags and devclass before the next probe. */ + child->devflags = 0; + if (!hasclass) + (void)device_set_devclass(child, NULL); + /* * Reset DF_QUIET in case this driver doesn't * end up as the best driver. @@ -2184,36 +2185,43 @@ break; } + if (best == NULL) + return (ENXIO); + /* * If we found a driver, change state and initialise the devclass. */ - if (best) { + if (pri < 0) { /* Set the winning driver, devclass, and flags. */ + result = device_set_driver(child, best->driver); + if (result != 0) + return (result); if (!child->devclass) { result = device_set_devclass(child, best->driver->name); - if (result != 0) + if (result != 0) { + (void)device_set_driver(child, NULL); return (result); + } } - result = device_set_driver(child, best->driver); - if (result != 0) - return (result); resource_int_value(best->driver->name, child->unit, "flags", &child->devflags); - if (pri < 0) { - /* - * A bit bogus. Call the probe method again to make - * sure that we have the right description. - */ - DEVICE_PROBE(child); + /* + * A bit bogus. Call the probe method again to make sure + * that we have the right description. + */ + result = DEVICE_PROBE(child); + if (result > 0) { + if (!hasclass) + (void)device_set_devclass(child, NULL); + (void)device_set_driver(child, NULL); + return (result); } - child->state = DS_ALIVE; - - bus_data_generation_update(); - return (0); } - return (ENXIO); + child->state = DS_ALIVE; + bus_data_generation_update(); + return (0); } /**