Page MenuHomeFreeBSD

snd_uaudio: Refactor umidi_attach()
AbandonedPublic

Authored by christos on Mar 17 2026, 6:36 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, May 18, 5:10 PM
Unknown Object (File)
Mon, May 18, 1:22 PM
Unknown Object (File)
Mon, May 18, 1:19 PM
Unknown Object (File)
Mon, May 18, 12:14 PM
Unknown Object (File)
Mon, May 18, 12:07 PM
Unknown Object (File)
Sun, May 17, 3:36 AM
Unknown Object (File)
Sun, May 17, 3:25 AM
Unknown Object (File)
Sat, May 9, 9:28 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.