Page MenuHomeFreeBSD

snd_uaudio: Refactor umidi_attach()
AbandonedPublic

Authored by christos on Mar 17 2026, 6:36 PM.
Tags
None
Referenced Files
F171374953: D55902.diff
Thu, Sep 10, 6:49 PM
F171317988: D55902.id.diff
Thu, Sep 10, 9:14 AM
F171301371: D55902.id173891.diff
Thu, Sep 10, 6:28 AM
F171298492: D55902.id173819.diff
Thu, Sep 10, 5:55 AM
Unknown Object (File)
Tue, Sep 8, 3:08 AM
Unknown Object (File)
Sun, Sep 6, 12:26 AM
Unknown Object (File)
Sat, Sep 5, 7:59 PM
Unknown Object (File)
Sat, Sep 5, 6:30 PM
Subscribers

Details

Summary

Merge umidi_init() with umidi_attach(). Also call umidi_detach() at the
detach label in umidi_attach(), similar to how uaudio_attach() does it.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

Diff Detail

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

Event Timeline

From what I can see, now, we initialize the mutex only if sc_midi_chan.valid is true, but we will destroy it unconditionally, so we might destroy an uninitialized mutex.

Address Mark's comment: if umidi_attach() fails, set sc->sc_midi_chan.valid to
0, and check that in umidi_detach().

sys/dev/sound/usb/uaudio.c
6080

But now we don't do any cleanup, e.g. of fifos, if umidi_attach() fails...

sys/dev/sound/usb/uaudio.c
6080

This is a good catch, although the fifo cleanup is not a problem, because the last point of failure in umidi_attach() is the fifo attach, so the only scenario where the fifos are actually attached and need cleanup, will be when umidi_attach() succeeds, in which case umidi_detach() will run normally.

The only thing that can potentially not get cleaned up with this code, is the usbd_transfer_setup().

I will address this.

christos retitled this revision from snd_uaudio: Merge umidi_init() with umidi_attach() to snd_uaudio: Refactor umidi_attach().Mar 20 2026, 11:39 AM
christos edited the summary of this revision. (Show Details)
sys/dev/sound/usb/uaudio.c
6067

So if umidi_attach() fails, we'll call umidi_detach() here, and then uaudio_attach() will call uaudio_detach(), which calls umidi_detach(). So we'll destroy the mutex twice.

sys/dev/sound/usb/uaudio.c
6067

True. I did test error paths to make sure this wouldn't be the case, but I must have missed something, because I didn't indeed hit this error. Now I tried manually making umidi_attach() fail and it does indeed destroy the mutex twice. Will address this now. Sorry for the noise.

I will come back to this at some other point, but it might require another series of patches, so abandoning this for now.