git: 83c8ec72ac6a - main - sound/midi: Pass the queue sizes as arguments to midi_init()

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Thu, 12 Nov 2026 16:38:21 UTC
The branch main has been updated by christos:

URL: https://cgit.FreeBSD.org/src/commit/?id=83c8ec72ac6acdad35aa0eaa053faf57ae34ea54

commit 83c8ec72ac6acdad35aa0eaa053faf57ae34ea54
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2026-11-12 11:01:14 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2026-11-12 16:35:50 +0000

    sound/midi: Pass the queue sizes as arguments to midi_init()
    
    There is no reason to have kobj methods for this.
    
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
---
 sys/dev/sound/midi/midi.c   | 13 ++++---------
 sys/dev/sound/midi/midi.h   |  3 ++-
 sys/dev/sound/midi/mpu401.c | 20 +++-----------------
 sys/dev/sound/midi/mpu_if.m | 14 ++++----------
 4 files changed, 13 insertions(+), 37 deletions(-)

diff --git a/sys/dev/sound/midi/midi.c b/sys/dev/sound/midi/midi.c
index 03f5907491ca..8ffe1a555725 100644
--- a/sys/dev/sound/midi/midi.c
+++ b/sys/dev/sound/midi/midi.c
@@ -144,24 +144,19 @@ midi_destroy(struct snd_midi *m)
  * softc.
  */
 struct snd_midi *
-midi_init(kobj_class_t cls, void *cookie)
+midi_init(kobj_class_t cls, void *cookie, size_t inqsize, size_t outqsize)
 {
 	struct make_dev_args args;
 	struct snd_midi *m;
-	size_t inqsize, outqsize;
 	uint8_t *ibuf = NULL;
 	uint8_t *obuf = NULL;
 	int err;
 
+	if (!inqsize && !outqsize)
+		return (NULL);
+
 	m = malloc(sizeof(*m), M_MIDI, M_WAITOK | M_ZERO);
 	kobj_init((kobj_t)m, cls);
-	inqsize = MPU_INQSIZE(m, cookie);
-	outqsize = MPU_OUTQSIZE(m, cookie);
-
-	if (!inqsize && !outqsize) {
-		kobj_delete((kobj_t)m, M_MIDI);
-		return (NULL);
-	}
 
 	mtx_init(&m->lock, "raw midi", NULL, 0);
 
diff --git a/sys/dev/sound/midi/midi.h b/sys/dev/sound/midi/midi.h
index 5c2301bf15ee..180911c6f9f0 100644
--- a/sys/dev/sound/midi/midi.h
+++ b/sys/dev/sound/midi/midi.h
@@ -44,7 +44,8 @@ MALLOC_DECLARE(M_MIDI);
 
 struct snd_midi;
 
-struct snd_midi *midi_init(kobj_class_t _mpu_cls, void *cookie);
+struct snd_midi *midi_init(kobj_class_t _mpu_cls, void *_cookie,
+    size_t _inqsize, size_t _outqsize);
 int	midi_uninit(struct snd_midi *_m);
 size_t	midi_out(struct snd_midi *_m, uint8_t *_buf, size_t _size);
 size_t	midi_in(struct snd_midi *_m, uint8_t *_buf, size_t _size);
diff --git a/sys/dev/sound/midi/mpu401.c b/sys/dev/sound/midi/mpu401.c
index 4c070952b595..20da11216c43 100644
--- a/sys/dev/sound/midi/mpu401.c
+++ b/sys/dev/sound/midi/mpu401.c
@@ -46,6 +46,8 @@
 #include "mpu_if.h"
 #include "mpufoi_if.h"
 
+#define MPU_QUEUE_SIZE	128
+
 #define CMD(m,d)	MPUFOI_WRITE(m, m->cookie, MPU_CMDPORT,d)
 #define STATUS(m)	MPUFOI_READ(m, m->cookie, MPU_STATPORT)
 #define READ(m)		MPUFOI_READ(m, m->cookie, MPU_DATAPORT)
@@ -65,15 +67,11 @@ static mpu401_intr_t mpu401_intr;
 
 static int mpu401_minit(struct snd_midi *, void *);
 static int mpu401_muninit(struct snd_midi *, void *);
-static size_t mpu401_minqsize(struct snd_midi *, void *);
-static size_t mpu401_moutqsize(struct snd_midi *, void *);
 static void mpu401_mcallback(struct snd_midi *, void *, int);
 
 static kobj_method_t mpu401_methods[] = {
 	KOBJMETHOD(mpu_init, mpu401_minit),
 	KOBJMETHOD(mpu_uninit, mpu401_muninit),
-	KOBJMETHOD(mpu_inqsize, mpu401_minqsize),
-	KOBJMETHOD(mpu_outqsize, mpu401_moutqsize),
 	KOBJMETHOD(mpu_callback, mpu401_mcallback),
 	KOBJMETHOD_END
 };
@@ -141,7 +139,7 @@ mpu401_init(kobj_class_t cls, void *cookie, driver_intr_t softintr,
 	m->si = softintr;
 	m->cookie = cookie;
 
-	m->mid = midi_init(&mpu401_class, m);
+	m->mid = midi_init(&mpu401_class, m, MPU_QUEUE_SIZE, MPU_QUEUE_SIZE);
 	if (!m->mid)
 		goto err;
 	*cb = mpu401_intr;
@@ -180,18 +178,6 @@ mpu401_muninit(struct snd_midi *sm __unused, void *arg)
 	return MPUFOI_UNINIT(m, m->cookie);
 }
 
-static size_t
-mpu401_minqsize(struct snd_midi *sm __unused, void *arg __unused)
-{
-	return 128;
-}
-
-static size_t
-mpu401_moutqsize(struct snd_midi *sm __unused, void *arg __unused)
-{
-	return 128;
-}
-
 static void
 mpu401_mcallback(struct snd_midi *sm __unused, void *arg, int flags)
 {
diff --git a/sys/dev/sound/midi/mpu_if.m b/sys/dev/sound/midi/mpu_if.m
index f62c4bd3231d..b9acb25b740d 100644
--- a/sys/dev/sound/midi/mpu_if.m
+++ b/sys/dev/sound/midi/mpu_if.m
@@ -1,6 +1,10 @@
 #-
 # Copyright (c) 2003 Mathew Kanner
 # All rights reserved.
+# Copyright (c) 2026 The FreeBSD Foundation
+#
+# Portions of this software were developed by Christos Margiolis
+# <christos@FreeBSD.org> under sponsorship from the FreeBSD Foundation.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -29,16 +33,6 @@
 
 INTERFACE mpu;
 
-METHOD size_t inqsize {
-	struct snd_midi *_kobj;
-	void   *_cookie;
-};
-
-METHOD size_t outqsize {
-	struct snd_midi *_kobj;
-	void   *_cookie;
-};
-
 METHOD int init {
 	struct snd_midi *_kobj;
 	void   *_cookie;