Page MenuHomeFreeBSD

asmc: resource cleanup simplifications
ClosedPublic

Authored by ngie on Feb 21 2026, 5:33 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Sep 23, 8:43 AM
Unknown Object (File)
Thu, Sep 10, 12:42 PM
Unknown Object (File)
Mon, Sep 7, 12:53 PM
Unknown Object (File)
Mon, Sep 7, 12:42 PM
Unknown Object (File)
Mon, Sep 7, 12:33 PM
Unknown Object (File)
Thu, Sep 3, 5:32 AM
Unknown Object (File)
Tue, Sep 1, 5:03 AM
Unknown Object (File)
Sat, Aug 29, 10:51 AM
Subscribers

Details

Summary

This change makes asmc_detach(..) reentrant by setting freed resources
to known invalid values when done, and makes asmc_attach(..) call
asmc_detach(..) instead of attempting to the semi-equivalent way of
cleaning up the driver resources allocated in asmc_detach(..).

Test Plan

I've been using this particular diff for some time now on a variety of Macs without issue, but all paths that have been tested are happy paths.

I should verify the pathological scenarios function as needed as well.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 70846
Build 67729: arc lint + arc unit

Event Timeline

ngie requested review of this revision.Feb 21 2026, 5:33 AM
ngie added reviewers: seuros, markj, adrian.

This works and has been stable in my testing for several weeks.

One issue remains: the sysctl context is not freed on teardown. The proper fix is the approach I implemented in:
https://github.com/freebsd/freebsd-src/commit/63eff205754c87d3f8e092c5f3a57a1ff2e3e2a2
(Note: I rebase often, so the SHA may change.)

I still reproduce a panic when unloading ASMC with an active Thunderbolt connection, so I havent updated D54615 yet. I need to trace the root cause.

That said, this can land as-is, the panic is reproducible with current code as well.

This revision is now accepted and ready to land.Feb 21 2026, 11:42 AM
In D55413#1267515, @guest-seuros wrote:

...

One issue remains: the sysctl context is not freed on teardown. The proper fix is the approach I implemented in:
https://github.com/freebsd/freebsd-src/commit/63eff205754c87d3f8e092c5f3a57a1ff2e3e2a2
(Note: I rebase often, so the SHA may change.)

If I'm reading the code correctly, this should happen automatically as part of device_detach: https://cgit.freebsd.org/src/tree/sys/kern/subr_bus.c#n2728 .

I still reproduce a panic when unloading ASMC with an active Thunderbolt connection, so I havent updated D54615 yet. I need to trace the root cause.

Is the problem in the USB code or the asmc(4) code?

This revision was automatically updated to reflect the committed changes.