Page MenuHomeFreeBSD

snd_uaudio: Refactor umidi_attach()
AbandonedPublic

Authored by christos on Tue, Mar 17, 6:36 PM.
Tags
None
Referenced Files
F151839091: D55902.id174008.diff
Sat, Apr 11, 12:38 AM
Unknown Object (File)
Tue, Apr 7, 9:09 PM
Unknown Object (File)
Tue, Apr 7, 3:59 PM
Unknown Object (File)
Mon, Apr 6, 11:48 PM
Unknown Object (File)
Mon, Apr 6, 5:11 PM
Unknown Object (File)
Sun, Apr 5, 3:10 PM
Unknown Object (File)
Sun, Apr 5, 11:47 AM
Unknown Object (File)
Sat, Apr 4, 1:14 AM
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().Fri, Mar 20, 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.