Bug 261071 - snd_midi: unit 0 cannot have 2 or more channels
Summary: snd_midi: unit 0 cannot have 2 or more channels
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.0-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: Christos Margiolis
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-10 03:30 UTC by masatic.bsd
Modified: 2026-01-09 23:29 UTC (History)
1 user (show)

See Also:


Attachments
patch, for 13.0-Release-p4 (2.31 KB, patch)
2022-01-10 03:30 UTC, masatic.bsd
no flags Details | Diff
midi.diff (2.39 KB, patch)
2025-02-24 08:28 UTC, Mark Linimon
no flags Details | Diff
midi.diff (2.42 KB, patch)
2025-02-24 08:31 UTC, Mark Linimon
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description masatic.bsd 2022-01-10 03:30:28 UTC
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.
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2025-02-24 08:28:52 UTC
Created attachment 257829 [details]
midi.diff

^Triage: attempt to rebase patch.
Comment 2 Mark Linimon freebsd_committer freebsd_triage 2025-02-24 08:31:02 UTC
Created attachment 257830 [details]
midi.diff

^Triage: attempt to rebase patch.
Comment 3 Christos Margiolis freebsd_committer freebsd_triage 2025-12-08 18:46:36 UTC
This is being addressed in a cleaner way in https://reviews.freebsd.org/D54126
Comment 4 commit-hook freebsd_committer freebsd_triage 2026-01-02 16:59:36 UTC
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(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2026-01-09 23:29:15 UTC
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(-)