Date: Fri, 02 Jan 2026 16:58:30 +0000
From: Christos Margiolis <christos@FreeBSD.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject: git: b9db6c212873 - main - sound: Improve snd_midi->{in,out}q allocation
Message-ID: <6957f936.24216.3c7bcf3e@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=b9db6c21287311b9e861893c065289d987a75804 commit b9db6c21287311b9e861893c065289d987a75804 Author: Christos Margiolis <christos@FreeBSD.org> AuthorDate: 2026-01-02 16:56:34 +0000 Commit: Christos Margiolis <christos@FreeBSD.org> CommitDate: 2026-01-02 16:58:06 +0000 sound: Improve snd_midi->{in,out}q allocation Currently we lock and allocate the buffers with M_NOWAIT, without checking if the return value of malloc(). This is not necessary as subsequent check below will eventually check that. However, for correctness, allocate the buffers with M_WAITOK (there is no reason not to) and lock afterwards. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D54131 --- sys/dev/sound/midi/midi.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/sys/dev/sound/midi/midi.c b/sys/dev/sound/midi/midi.c index 9b61e972fab9..7f968b6210f5 100644 --- a/sys/dev/sound/midi/midi.c +++ b/sys/dev/sound/midi/midi.c @@ -109,7 +109,8 @@ midi_init(kobj_class_t cls, void *cookie) { struct snd_midi *m; int inqsize, outqsize; - uint8_t *buf; + uint8_t *ibuf = NULL; + uint8_t *obuf = NULL; m = malloc(sizeof(*m), M_MIDI, M_WAITOK | M_ZERO); kobj_init((kobj_t)m, cls); @@ -121,26 +122,17 @@ midi_init(kobj_class_t cls, void *cookie) mtx_init(&m->lock, "raw midi", NULL, 0); - mtx_lock(&m->lock); - if (inqsize) - buf = malloc(sizeof(uint8_t) * inqsize, M_MIDI, M_NOWAIT); - else - buf = NULL; + ibuf = malloc(inqsize, M_MIDI, M_WAITOK); + if (outqsize) + obuf = malloc(outqsize, M_MIDI, M_WAITOK); - MIDIQ_INIT(m->inq, buf, inqsize); + mtx_lock(&m->lock); - if (outqsize) - buf = malloc(sizeof(uint8_t) * outqsize, M_MIDI, M_NOWAIT); - else - buf = NULL; m->hiwat = outqsize / 2; - MIDIQ_INIT(m->outq, buf, outqsize); - - if ((inqsize && !MIDIQ_BUF(m->inq)) || - (outqsize && !MIDIQ_BUF(m->outq))) - goto err2; + MIDIQ_INIT(m->inq, ibuf, inqsize); + MIDIQ_INIT(m->outq, obuf, outqsize); m->flags = 0; m->unit = alloc_unr(dev_unr);home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6957f936.24216.3c7bcf3e>
