When dealing with device trees, parent devices needs to be detached first, then children, if any.
Details
Diff Detail
- Repository
- rS FreeBSD src repository - subversion
- Lint
Lint Skipped - Unit
Tests Skipped - Build Status
Buildable 5367 Build 5558: CI src build Jenkins
Event Timeline
sys/kern/subr_bus.c | ||
---|---|---|
1962–1963 | I would actually do the detach in the opposite order (parent first) as many drivers do explicit detach/delete of child devices in their detach routines. We have had drivers crash in the past when the grandchildren are detached/deleted out from under them. |
I don't feel this approach better. If device driver detaches its children by itself, then duplicating it here is pointless. On the other side, if driver does not detach its children (shouldn't all drivers do it?), then they can be pretty surprised when their parent disappears from under them at some moment without warning.
It's not quite pointless. What drivers find surprising is that children get deleted out from under them before their detach routine is called and then when they try to detach them they are using an already-free'd pointer. It is best to detach the driver first and then go through cleaning up any dangling devices. For the cleaning up of dangling (but detached) devices, you certainly need to remove children before parents. However, detach of a subtree of devices normally is initiated by the parent device's detach routine using bus_generic_detach() to do a depth-first tree walk detaching drivers.