Date: Fri, 09 Jan 2026 23:27:54 +0000
From: Christos Margiolis <christos@FreeBSD.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject: git: 0ed90f4379c4 - stable/15 - sound: Improve snd_midi->{in,out}q allocation
Message-ID: <69618efa.30df1.665dd6d7@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/15 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=0ed90f4379c4cb8a5e3e340c6a9cfc63897ae059 commit 0ed90f4379c4cb8a5e3e340c6a9cfc63897ae059 Author: Christos Margiolis <christos@FreeBSD.org> AuthorDate: 2026-01-02 16:56:34 +0000 Commit: Christos Margiolis <christos@FreeBSD.org> CommitDate: 2026-01-09 23:27:24 +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 (cherry picked from commit b9db6c21287311b9e861893c065289d987a75804) --- 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?69618efa.30df1.665dd6d7>
