Skip to content

Commit 0759e77

Browse files
committed
ALSA: usb-audio: Fix duplicated name in MIDI substream names
The MIDI substream name string is constructed from the combination of the card shortname (which is taken from USB iProduct) and the USB iJack. The problem is that some devices put the product name to the iJack field, too. For example, aplaymidi -l output on the Lanchkey MK 49 are like: % aplaymidi -l Port Client name Port name 44:0 Launchkey MK4 49 Launchkey MK4 49 Launchkey MK4 44:1 Launchkey MK4 49 Launchkey MK4 49 Launchkey MK4 where the actual iJack name can't be seen because it's truncated due to the doubly words. For resolving those situations, this patch compares the iJack string with the card shortname, and drops if both start with the same words. Then the result becomes like: % aplaymidi -l Port Client name Port name 40:0 Launchkey MK4 49 Launchkey MK4 49 MIDI In 40:1 Launchkey MK4 49 Launchkey MK4 49 DAW In A caveat is that there are some pre-defined names for certain devices in the driver code, and this workaround shouldn't be applied to them. Similarly, when the iJack isn't specified, we should skip this check, too. The patch added those checks in addition to the string comparison. Suggested-by: Paul Davis <[email protected]> Tested-by: Paul Davis <[email protected]> Link: https://lore.kernel.org/CAFa_cKmEDQWcJatbYWi6A58Zg4Ma9_6Nr3k5LhqwyxC-P_kXtw@mail.gmail.com Link: https://patch.msgid.link/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 56f1f30 commit 0759e77

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

sound/usb/midi.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,10 +1885,18 @@ static void snd_usbmidi_init_substream(struct snd_usb_midi *umidi,
18851885
}
18861886

18871887
port_info = find_port_info(umidi, number);
1888-
name_format = port_info ? port_info->name :
1889-
(jack_name != default_jack_name ? "%s %s" : "%s %s %d");
1890-
snprintf(substream->name, sizeof(substream->name),
1891-
name_format, umidi->card->shortname, jack_name, number + 1);
1888+
if (port_info || jack_name == default_jack_name ||
1889+
strncmp(umidi->card->shortname, jack_name, strlen(umidi->card->shortname)) != 0) {
1890+
name_format = port_info ? port_info->name :
1891+
(jack_name != default_jack_name ? "%s %s" : "%s %s %d");
1892+
snprintf(substream->name, sizeof(substream->name),
1893+
name_format, umidi->card->shortname, jack_name, number + 1);
1894+
} else {
1895+
/* The manufacturer included the iProduct name in the jack
1896+
* name, do not use both
1897+
*/
1898+
strscpy(substream->name, jack_name);
1899+
}
18921900

18931901
*rsubstream = substream;
18941902
}

0 commit comments

Comments
 (0)