Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: rawmidi: Make tied_device=0 as default / unknown

In the original change, rawmidi_info.tied_device showed -1 for the
unknown or untied device. But this would require the user-space to
check the protocol version and judge the value conditionally, which
is rather error-prone.

Instead, set the tied_device = 0 to be default as unknown, and
indicate the real device with the offset 1, for achieving more
backward compatibility.

Suggested-by: Jaroslav Kysela <perex@perex.cz>
Link: https://patch.msgid.link/20250114104711.19197-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+11 -4
+9
include/sound/rawmidi.h
··· 191 191 long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream, 192 192 const unsigned char *buf, long count); 193 193 194 + /* set up the tied devices */ 195 + static inline void snd_rawmidi_tie_devices(struct snd_rawmidi *r1, 196 + struct snd_rawmidi *r2) 197 + { 198 + /* tied_device field keeps the device+1 (so that 0 being unknown) */ 199 + r1->tied_device = r2->device + 1; 200 + r2->tied_device = r1->device + 1; 201 + } 202 + 194 203 #endif /* __SOUND_RAWMIDI_H */
+1 -1
include/uapi/sound/asound.h
··· 730 730 #define SNDRV_RAWMIDI_INFO_UMP 0x00000008 731 731 #define SNDRV_RAWMIDI_INFO_STREAM_INACTIVE 0x00000010 732 732 733 - #define SNDRV_RAWMIDI_DEVICE_UNKNOWN -1 733 + #define SNDRV_RAWMIDI_DEVICE_UNKNOWN 0 734 734 735 735 struct snd_rawmidi_info { 736 736 unsigned int device; /* RO/WR (control): device number */
-1
sound/core/rawmidi.c
··· 1837 1837 INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams); 1838 1838 INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams); 1839 1839 rmidi->info_flags = info_flags; 1840 - rmidi->tied_device = SNDRV_RAWMIDI_DEVICE_UNKNOWN; 1841 1840 1842 1841 if (id != NULL) 1843 1842 strscpy(rmidi->id, id, sizeof(rmidi->id));
+1 -2
sound/core/ump.c
··· 1382 1382 ump_legacy_set_rawmidi_name(ump); 1383 1383 update_legacy_names(ump); 1384 1384 1385 - rmidi->tied_device = ump->core.device; 1386 - ump->core.tied_device = rmidi->device; 1385 + snd_rawmidi_tie_devices(rmidi, &ump->core); 1387 1386 1388 1387 ump_dbg(ump, "Created a legacy rawmidi #%d (%s)\n", device, id); 1389 1388 return 0;