Page MenuHomeFreeBSD

Fix device delete child function
ClosedPublic

Authored by hselasky on Sep 29 2016, 8:07 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, May 7, 11:12 PM
Unknown Object (File)
Tue, May 7, 11:06 PM
Unknown Object (File)
Wed, May 1, 10:11 PM
Unknown Object (File)
Wed, May 1, 10:01 PM
Unknown Object (File)
Wed, May 1, 10:00 PM
Unknown Object (File)
Wed, May 1, 10:00 PM
Unknown Object (File)
Wed, May 1, 9:59 PM
Unknown Object (File)
Wed, May 1, 9:59 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 Not Applicable
Unit
Tests Not Applicable

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
1990 ↗(On Diff #20801)

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.