aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos Margiolis <christos@FreeBSD.org>2026-01-02 16:56:34 +0000
committerChristos Margiolis <christos@FreeBSD.org>2026-01-02 16:58:06 +0000
commitb9db6c21287311b9e861893c065289d987a75804 (patch)
tree9c2b90ea4d5457ce7c274c1183b93161a023f17f
parent3b9e776498a7e3e96c1a351fdd561f25803718df (diff)
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
-rw-r--r--sys/dev/sound/midi/midi.c24
1 files 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);