git: d912ea5879cd - main - sound: Merge midi_destroy() with midi_uninit()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 02 Jan 2026 16:58:24 UTC
The branch main has been updated by christos:
URL: https://cgit.FreeBSD.org/src/commit/?id=d912ea5879cd6b1042671ae3986d496c63be4d49
commit d912ea5879cd6b1042671ae3986d496c63be4d49
Author: Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2026-01-02 16:56:19 +0000
Commit: Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2026-01-02 16:58:05 +0000
sound: Merge midi_destroy() with midi_uninit()
Also always call MPU_UNINIT(). It does not make sense not to if we are
deallocating everything.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D54192
---
sys/dev/sound/midi/midi.c | 57 ++++++++++++-----------------------------------
1 file changed, 14 insertions(+), 43 deletions(-)
diff --git a/sys/dev/sound/midi/midi.c b/sys/dev/sound/midi/midi.c
index 901e098d4883..2567f7412eb8 100644
--- a/sys/dev/sound/midi/midi.c
+++ b/sys/dev/sound/midi/midi.c
@@ -97,8 +97,6 @@ static struct cdevsw midi_cdevsw = {
.d_name = "rmidi",
};
-static int midi_destroy(struct snd_midi *, int);
-
struct unrhdr *dev_unr = NULL;
struct unrhdr *chn_unr = NULL;
@@ -186,21 +184,15 @@ err1:
return NULL;
}
-/*
- * midi_uninit does not call MIDI_UNINIT, as since this is the implementors
- * entry point. midi_uninit if fact, does not send any methods. A call to
- * midi_uninit is a defacto promise that you won't manipulate ch anymore
- */
int
midi_uninit(struct snd_midi *m)
{
- int err;
-
- err = EBUSY;
mtx_lock(&m->lock);
if (m->busy) {
- if (!(m->rchan || m->wchan))
- goto err;
+ if (!(m->rchan || m->wchan)) {
+ mtx_unlock(&m->lock);
+ return (EBUSY);
+ }
if (m->rchan) {
wakeup(&m->rchan);
@@ -211,14 +203,17 @@ midi_uninit(struct snd_midi *m)
m->wchan = 0;
}
}
- err = midi_destroy(m, 0);
- if (!err)
- goto exit;
-
-err:
mtx_unlock(&m->lock);
-exit:
- return err;
+ MPU_UNINIT(m, m->cookie);
+ destroy_dev(m->dev);
+ free_unr(dev_unr, m->unit);
+ free_unr(chn_unr, m->channel);
+ free(MIDIQ_BUF(m->inq), M_MIDI);
+ free(MIDIQ_BUF(m->outq), M_MIDI);
+ mtx_destroy(&m->lock);
+ free(m, M_MIDI);
+
+ return (0);
}
#ifdef notdef
@@ -601,30 +596,6 @@ midi_poll(struct cdev *i_dev, int events, struct thread *td)
return (revents);
}
-/*
- * Single point of midi destructions.
- */
-static int
-midi_destroy(struct snd_midi *m, int midiuninit)
-{
- mtx_assert(&m->lock, MA_OWNED);
-
- MIDI_DEBUG(3, printf("midi_destroy\n"));
- m->dev->si_drv1 = NULL;
- mtx_unlock(&m->lock); /* XXX */
- destroy_dev(m->dev);
- /* XXX */
- if (midiuninit)
- MPU_UNINIT(m, m->cookie);
- free_unr(dev_unr, m->unit);
- free_unr(chn_unr, m->channel);
- free(MIDIQ_BUF(m->inq), M_MIDI);
- free(MIDIQ_BUF(m->outq), M_MIDI);
- mtx_destroy(&m->lock);
- free(m, M_MIDI);
- return 0;
-}
-
static void
midi_sysinit(void *data __unused)
{