Page MenuHomeFreeBSD

snd_uaudio: Refactor umidi_attach()
Needs ReviewPublic

Authored by christos on Tue, Mar 17, 6:36 PM.

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.