Page MenuHomeFreeBSD

Fix device delete child function
ClosedPublic

Authored by hselasky on Sep 29 2016, 8:07 AM.
Tags
None
Referenced Files
F103521233: D8070.id20856.diff
Tue, Nov 26, 1:30 AM
Unknown Object (File)
Sun, Nov 24, 10:42 PM
Unknown Object (File)
Sun, Nov 24, 2:58 PM
Unknown Object (File)
Sun, Nov 24, 5:21 AM
Unknown Object (File)
Tue, Nov 19, 9:24 PM
Unknown Object (File)
Tue, Nov 19, 3:05 PM
Unknown Object (File)
Tue, Nov 19, 1:23 PM
Unknown Object (File)
Tue, Nov 19, 1:05 PM
Subscribers

Details

Summary

When dealing with device trees, parent devices needs to be detached first, then children, if any.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 5366
Build 5557: CI src buildJenkins

Event Timeline

hselasky retitled this revision from to Fix device delete child function.
hselasky updated this object.
hselasky edited the test plan for this revision. (Show Details)
hselasky added a reviewer: jhb.
hselasky set the repository for this revision to rS FreeBSD src repository - subversion.

Remove not needed return code from device_delete_familiy()

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.

hselasky updated this object.

Update patch as per suggestions.

Also fix the same issue in the FreeBSD kshim for bootloaders.

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.

In D8070#167522, @mav wrote:

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.

In D8070#167540, @jhb wrote:

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.

OK, assuming that detaching device driver detaches its children it looks fine.

jhb edited edge metadata.
This revision is now accepted and ready to land.Oct 13 2016, 8:05 PM
This revision was automatically updated to reflect the committed changes.