Created attachment 230855 [details] patch, for 13.0-Release-p4 midi_init uses 0 as auto-allocate unit number, but unit 0 is also a valid unit number. This confliction makes secondary function call to allocate another channel for unit 0 is treated as auto-allocate and returns non-0 unit as result incorrectly. Attached patch fixes this problem, auto-allocate number is changed from 0 to -1.
Created attachment 257829 [details] midi.diff ^Triage: attempt to rebase patch.
Created attachment 257830 [details] midi.diff ^Triage: attempt to rebase patch.
This is being addressed in a cleaner way in https://reviews.freebsd.org/D54126
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=c508be8ca9578ef6e3e4b31de1baca8038c0e0ae commit c508be8ca9578ef6e3e4b31de1baca8038c0e0ae Author: Christos Margiolis <christos@FreeBSD.org> AuthorDate: 2026-01-02 16:56:02 +0000 Commit: Christos Margiolis <christos@FreeBSD.org> CommitDate: 2026-01-02 16:58:05 +0000 sound: Retire midi_devs and mstat_lock Nowadays midi_devs only has two uses: 1. To verify in midi_init() if a given device unit exists, as well as to calculate the next device unit. Instead, make sure we always get a unique unit and channel number using unr(9). 2. To keep track of all midi devices, so that it can destroy them all at once in midi_sysuninit(). However, since we stopped building midi as a kernel module, there is no reason to do that, simply let the drivers tear down the devices themselves. Also retire mstat_lock since it's only used to protect midi_devs. PR: 261071 Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D54126 sys/dev/sound/midi/midi.c | 130 ++++++++------------------------------------ sys/dev/sound/midi/midi.h | 7 +-- sys/dev/sound/midi/mpu401.c | 2 +- 3 files changed, 26 insertions(+), 113 deletions(-)
A commit in branch stable/15 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=3e04a082687cbb5a8e052f156c6e7ebd03876284 commit 3e04a082687cbb5a8e052f156c6e7ebd03876284 Author: Christos Margiolis <christos@FreeBSD.org> AuthorDate: 2026-01-02 16:56:02 +0000 Commit: Christos Margiolis <christos@FreeBSD.org> CommitDate: 2026-01-09 23:27:23 +0000 sound: Retire midi_devs and mstat_lock Nowadays midi_devs only has two uses: 1. To verify in midi_init() if a given device unit exists, as well as to calculate the next device unit. Instead, make sure we always get a unique unit and channel number using unr(9). 2. To keep track of all midi devices, so that it can destroy them all at once in midi_sysuninit(). However, since we stopped building midi as a kernel module, there is no reason to do that, simply let the drivers tear down the devices themselves. Also retire mstat_lock since it's only used to protect midi_devs. PR: 261071 Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D54126 (cherry picked from commit c508be8ca9578ef6e3e4b31de1baca8038c0e0ae) sys/dev/sound/midi/midi.c | 130 ++++++++------------------------------------ sys/dev/sound/midi/midi.h | 7 +-- sys/dev/sound/midi/mpu401.c | 2 +- 3 files changed, 26 insertions(+), 113 deletions(-)