ALSA: ump: clear stale RPN selector on NRPN change
PATCH 1/2 ALSA: ump: clear stale RPN selector on NRPN change
The legacy-to-UMP converter keeps separate RPN and NRPN selector flags. When a stream changes selector type without sending data first, both flags remain set and fill_rpn() gives RPN priority, so subsequent NRPN data is emitted as RPN.
Clear the previous selector flag after flushing any pending parameter data and before recording the newly selected parameter type.
--- sound/core/ump_convert.c | 4 ++++ 1 file changed, 4 insertions(+)
sound/core/ump_convert.c +4 -0
@@ -378,6 +378,7 @@ static int cvt_legacy_cmd_to_ump(struct ump_cvt_to_ump *cvt,switch (buf[1 ]) {case UMP_CC_RPN_MSB : ret =fill_rpn (cc, midi2, true); + cc->nrpn_set =0 ; cc->rpn_set =1 ; cc->cc_rpn_msb = buf[2 ];if (cc->cc_rpn_msb ==0x7f && cc->cc_rpn_lsb ==0x7f )
@@ -385,6 +386,7 @@ static int cvt_legacy_cmd_to_ump(struct ump_cvt_to_ump *cvt,return ret;case UMP_CC_RPN_LSB : ret =fill_rpn (cc, midi2, true); + cc->nrpn_set =0 ; cc->rpn_set =1 ; cc->cc_rpn_lsb = buf[2 ];if (cc->cc_rpn_msb ==0x7f && cc->cc_rpn_lsb ==0x7f )
@@ -392,11 +394,13 @@ static int cvt_legacy_cmd_to_ump(struct ump_cvt_to_ump *cvt,return ret;case UMP_CC_NRPN_MSB : ret =fill_rpn (cc, midi2, true); + cc->rpn_set =0 ; cc->nrpn_set =1 ; cc->cc_nrpn_msb = buf[2 ];return ret;case UMP_CC_NRPN_LSB : ret =fill_rpn (cc, midi2, true); + cc->rpn_set =0 ; cc->nrpn_set =1 ; cc->cc_nrpn_lsb = buf[2 ];return ret;
PATCH 2/2 ALSA: ump: clear stale selectors in sequencer conversion
The sequencer MIDI 2.0 converter tracks RPN and NRPN selection flags separately. When the controller stream switches selector type, the previous flag remains set; fill_rpn() checks RPN first and can encode subsequent NRPN data as RPN.
Flush pending parameter data with the old selector, then clear the opposite selector before recording new state in both CC and Control14 event paths. Add KUnit coverage for both transition directions, pending flushes, null RPN, channel isolation, and MIDI 1.0 conversion.
--- sound/core/seq/Kconfig | 12 ++ sound/core/seq/seq_ump_convert.c | 275 +++++++++++++++++++++++++++++++ 2 files changed, 287 insertions(+)
sound/core/seq/Kconfig +12 -0
@@ -76,4 +76,16 @@ config SND_SEQ_UMP config SND_SEQ_UMP_CLIENT def_tristate SND_UMP && SND_SEQ_UMP +config SND_SEQ_UMP_KUNIT_TEST + bool "KUnit tests for ALSA sequencer UMP conversion" if !KUNIT_ALL_TESTS + depends on KUNIT + depends on SND_SEQUENCER=y && SND_SEQ_UMP + depends on SND_UMP=y && SND_UMP_LEGACY_RAWMIDI + default KUNIT_ALL_TESTS + help + Tests RPN/NRPN selector transitions through the Controller and + Control14 sequencer event paths. It covers pending-data flushes, + null-RPN reset, per-channel state isolation, and legacy MIDI 1.0 + protocol conversion. The suite requires no MIDI hardware. + endif # SND_SEQUENCER
sound/core/seq/seq_ump_convert.c +275 -0
319 lines not on this page · raw message
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] ALSA: ump: missing Fixes trailer in commit message It also noticed 1 related pre-existing issue this…
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] ALSA: ump: missing Fixes trailer in commit message It also noticed 1 related pre-existing issue this patch does not introduce:
- [Medium] ALSA: ump: improper RPN/NRPN state reset in reset_rpn() [1] --
commit e95e219dab86391e1d43f84e1ce499ca3011380d
Author: Alyandra Zahran Nadhir <[email protected]>
Quoted 11 lines
ALSA: ump: clear stale RPN selector on NRPN change
The legacy-to-UMP converter keeps separate RPN and NRPN selector flags. When a stream changes selector type without sending data first, both flags remain set and
fill_rpn()gives RPN priority, so subsequent NRPN data is emitted as RPN.Clear the previous selector flag after flushing any pending parameter data and before recording the newly selected parameter type.
Signed-off-by Alyandra Zahran Nadhir <[email protected]>
[Severity: Low]
This fixes a bug in the legacy MIDI to UMP RPN/NRPN converter. Should it include:
sound/core/ump_convert.c static int cvt_legacy_cmd_to_ump(struct ump_cvt_to_ump *cvt, · line 384
Quoted 12 lines
sound/core/ump_convert.c +1
-0@@ -378,6 +378,7 @@ static int cvt_legacy_cmd_to_ump(struct ump_cvt_to_ump *cvt,switch (buf[1 ]) {case UMP_CC_RPN_MSB : ret =fill_rpn (cc, midi2, true); + cc->nrpn_set =0 ; cc->rpn_set =1 ; cc->cc_rpn_msb = buf[2 ];if (cc->cc_rpn_msb ==0x7f && cc->cc_rpn_lsb ==0x7f )
[Severity: Medium]
This problem wasn't introduced by this patch, but does fill_rpn() calling reset_rpn() [1] drop consecutive Data Entry updates for the same parameter?
In MIDI 1.0, an RPN or NRPN selection stays active across multiple Data Entry messages until a new parameter is selected or RPN Null (0x7f/0x7f) is sent. However, fill_rpn() calls reset_rpn(cc) after emitting the first UMP packet, clearing cc->rpn_set, cc->nrpn_set, and cc->cc_rpn_msb/lsb along with the data flags. Any subsequent Data Entry message for that same parameter then sees neither rpn_set nor nrpn_set set in fill_rpn() and is silently dropped.
[1] https://sashiko.dev/#/bug/linux-552af5af-5e38-4c5d-9b46-76886460e72d
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH 2/2] ALSA: ump: clear stale selectors in sequencer conversion
In reply to Alyandra Zahran NadhirThank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] ALSA: seq: SND_SEQ_UMP_KUNIT_TEST depends on KUNIT instead of KUNIT=y - [Medium] ALSA: ump: stale…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] ALSA: seq: SND_SEQ_UMP_KUNIT_TEST depends on KUNIT instead of KUNIT=y
- [Medium] ALSA: ump: stale RPN/NRPN MSB/LSB bytes kept on selector switch in cc_ev_to_ump_midi2()
- [Low] ALSA: seq: missing Fixes trailer for stale RPN/NRPN selector fix --
commit 7687b62a51dd971356b5f3418762bb460cd2266c
Author: Alyandra Zahran Nadhir <[email protected]>
Quoted 7 lines
ALSA: ump: clear stale selectors in sequencer conversion
The sequencer MIDI 2.0 converter tracks RPN and NRPN selection flags separately. When the controller stream switches selector type, the previous flag remains set;
fill_rpn()checks RPN first and can encode subsequent NRPN data as RPN.
Quoted 6 lines
Flush pending parameter data with the old selector, then clear the opposite selector before recording new state in both CC and Control14 event paths. Add KUnit coverage for both transition directions, pending flushes, null RPN, channel isolation, and MIDI 1.0 conversion.
Signed-off-by Alyandra Zahran Nadhir <[email protected]>
[Severity: Low]
Should this bug fix include a Fixes tag?
Quoted 5 lines
sound/core/seq/Kconfig +0
-0
sound/core/seq/Kconfig config SND_SEQ_UMP · line 84
Quoted 9 lines
sound/core/seq/Kconfig +6
-0@@ -76,4 +76,16 @@ config SND_SEQ_UMP config SND_SEQ_UMP_CLIENT def_tristate SND_UMP && SND_SEQ_UMP +config SND_SEQ_UMP_KUNIT_TEST + bool "KUnit tests for ALSA sequencer UMP conversion" if !KUNIT_ALL_TESTS + depends on KUNIT + depends on SND_SEQUENCER=y && SND_SEQ_UMP + depends on SND_UMP=y && SND_UMP_LEGACY_RAWMIDI + default KUNIT_ALL_TESTS
[Severity: Medium]
Does SND_SEQ_UMP_KUNIT_TEST need to depend on KUNIT=y instead of KUNIT?
SND_SEQ_UMP_KUNIT_TEST is a bool option compiled into built-in seq_ump_convert.o (since SND_SEQUENCER=y and SND_UMP=y are required). When CONFIG_KUNIT=m and CONFIG_SND_SEQ_UMP_KUNIT_TEST=y, linking vmlinux fails with undefined references to kunit_kmalloc_array() and the KUnit assertion helpers residing in kunit.ko.
[ ... ]
Quoted 4 lines
sound/core/seq/seq_ump_convert.c +0
-0
[ ... ]
Quoted 20 lines
sound/core/seq/seq_ump_convert.c +1
-0@@ -847,6 +851,7 @@ static int cc_ev_to_ump_midi2(const struct snd_seq_event *event,switch (index) {case UMP_CC_RPN_MSB : ret =fill_rpn (cc, data, channel, true); + cc->nrpn_set =0 ; cc->rpn_set =1 ; cc->cc_rpn_msb = val;if (cc->cc_rpn_msb ==0x7f && cc->cc_rpn_lsb ==0x7f )sound/core/seq/seq_ump_convert.c +1
-0reset_rpn (cc);break ;case UMP_CC_RPN_LSB : ret =fill_rpn (cc, data, channel, true); + cc->nrpn_set =0 ; cc->rpn_set =1 ; cc->cc_rpn_lsb = val;if (cc->cc_rpn_msb ==0x7f && cc->cc_rpn_lsb ==0x7f )reset_rpn (cc);break ;case UMP_CC_NRPN_MSB : ret =fill_rpn (cc, data, channel, true);
sound/core/seq/seq_ump_convert.c static int cc_ev_to_ump_midi2(const struct snd_seq_event *event, · line 879
Quoted 10 lines
sound/core/seq/seq_ump_convert.c +2
-0+ cc->rpn_set =0 ; cc->nrpn_set =1 ; cc->cc_nrpn_msb = val;break ;case UMP_CC_NRPN_LSB : ret =fill_rpn (cc, data, channel, true); + cc->rpn_set =0 ; cc->nrpn_set =1 ; cc->cc_nrpn_lsb = val;break ;
[Severity: Medium]
Can switching between RPN and NRPN in cc_ev_to_ump_midi2() still leave stale cc_rpn_msb/cc_rpn_lsb and cc_nrpn_msb/cc_nrpn_lsb values behind?
When no data bytes are pending, fill_rpn() returns early without calling reset_rpn(), and clearing only rpn_set or nrpn_set leaves the opposite selector's MSB/LSB bytes intact (and reset_rpn() itself never clears cc_nrpn_msb or cc_nrpn_lsb).
If a channel sets cc_rpn_lsb = 0x7f (such as RPN 0x00:0x7f) without sending data, switches to NRPN, and later sends a two-message Null RPN (UMP_CC_RPN_MSB = 0x7f followed by UMP_CC_RPN_LSB = 0x7f), the first message sees cc_rpn_msb == 0x7f and the stale cc_rpn_lsb == 0x7f and calls reset_rpn() prematurely. The second message (UMP_CC_RPN_LSB = 0x7f) then sets rpn_set = 1 and cc_rpn_lsb = 0x7f with cc_rpn_msb == 0, leaving RPN 0x00:0x7f active instead of deselecting parameters.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Quoted 10 lines · Alyandra Zahran Nadhir
The legacy-to-UMP converter keeps separate RPN and NRPN selector flags. When a stream changes selector type without sending data first, both flags remain set and
fill_rpn()gives RPN priority, so subsequent NRPN data is emitted as RPN.Clear the previous selector flag after flushing any pending parameter data and before recording the newly selected parameter type.
Signed-off-by Alyandra Zahran Nadhir <[email protected]>
Thanks for the patch.
Recently there was a discussion about RPN/NRPN handling, and this looks related:
https://lore.kernel.org/[email protected]
Adding HyeongJun to Cc.
Takashi
Quoted 38 lines
--- sound/core/ump_convert.c | 4 ++++ 1 file changed, 4 insertions(+)sound/core/ump_convert.c +4
-0@@ -378,6 +378,7 @@ static int cvt_legacy_cmd_to_ump(struct ump_cvt_to_ump *cvt,switch (buf[1 ]) {case UMP_CC_RPN_MSB : ret =fill_rpn (cc, midi2, true); + cc->nrpn_set =0 ; cc->rpn_set =1 ; cc->cc_rpn_msb = buf[2 ];if (cc->cc_rpn_msb ==0x7f && cc->cc_rpn_lsb ==0x7f )@@ -385,6 +386,7 @@ static int cvt_legacy_cmd_to_ump(struct ump_cvt_to_ump *cvt,return ret;case UMP_CC_RPN_LSB : ret =fill_rpn (cc, midi2, true); + cc->nrpn_set =0 ; cc->rpn_set =1 ; cc->cc_rpn_lsb = buf[2 ];if (cc->cc_rpn_msb ==0x7f && cc->cc_rpn_lsb ==0x7f )@@ -392,11 +394,13 @@ static int cvt_legacy_cmd_to_ump(struct ump_cvt_to_ump *cvt,return ret;case UMP_CC_NRPN_MSB : ret =fill_rpn (cc, midi2, true); + cc->rpn_set =0 ; cc->nrpn_set =1 ; cc->cc_nrpn_msb = buf[2 ];return ret;case UMP_CC_NRPN_LSB : ret =fill_rpn (cc, midi2, true); + cc->rpn_set =0 ; cc->nrpn_set =1 ; cc->cc_nrpn_lsb = buf[2 ];return ret;
Hello Takashi,
Thanks for adding me, and thanks Alyandra for the patches. Yes, this is one of the cases from that thread.
I have patches for the other cases discussed there. They keep the RPN/NRPN selection after a send and clear only the data, drop data when nothing is selected, and handle a Null NRPN like a Null RPN. They also need the same selector change as this patch.
I can send them on top of Alyandra's patches, or as one series that includes the selector change, whichever you prefer.
Best regards,
HyeongJun An
Quoted 9 lines · Alyandra SigmabetJir
Hi HyeongJun,
Thank you for bringing up these related cases in the earlier discussion. I also appreciate you taking the time to work on the additional patches.
Thank you for clarifying the situation and sharing the details.I appreciate your help and the work you've already put into this.
Could you guys cooperate and organize a single fix series? That'd be nicer at merge.
Also, about the unit test: I'm not much against kunit, but my gut feeling is that selftest would be more flexible (and less changes in the core code itself). If that's feasible, let's go in that way. Otherwise we can take the kunit change. But maybe it's cleaner to move the test code into another file.
thanks,
Takashi
Quoted 22 lines
Sincerely,
AlyandraPada Sab, 7 Nov 2026 21.29, HyeongJun An <[email protected]> menulis:
Hello Takashi,
Thanks for adding me, and thanks Alyandra for the patches. Yes, this is one of the cases from that thread.
I have patches for the other cases discussed there. They keep the RPN/NRPN selection after a send and clear only the data, drop data when nothing is selected, and handle a Null NRPN like a Null RPN. They also need the same selector change as this patch.
I can send them on top of Alyandra's patches, or as one series that includes the selector change, whichever you prefer.
Best regards,
HyeongJun An
Hello Takashi and Alyandra,
Sure. I'll put Alyandra's patches first and mine on top, without the KUnit part.
For tests, I have a sequencer test that I used for these changes, and I can turn it into a selftest as a separate patch, with Alyandra's KUnit cases added.
Alyandra, would that be okay with you?
Best regards,
HyeongJun An
Hello HyeongJun and Takashi,
Yes, that sounds good to me.
I'm happy with putting my patches first, followed by yours, and moving the tests into a separate selftest patch.
Thanks for offering to adapt the sequencer test and incorporate my test cases. I think this would be a cleaner approach.
Best regards,
Alyandra