Index: kern/subr_bus.c =================================================================== --- kern/subr_bus.c +++ kern/subr_bus.c @@ -1949,6 +1949,10 @@ PDEBUG(("%s from %s", DEVICENAME(child), DEVICENAME(dev))); + /* detach parent before deleting children, if any */ + if ((error = device_detach(child)) != 0) + return (error); + /* remove children first */ while ((grandchild = TAILQ_FIRST(&child->children)) != NULL) { error = device_delete_child(child, grandchild); @@ -1956,8 +1960,6 @@ return (error); } - if ((error = device_detach(child)) != 0) - return (error); if (child->devclass) devclass_delete_device(child->devclass, child); if (child->parent)