Skip to content

Commit 3846699

Browse files
committed
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 3784950 commit 3846699

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

include/sound/rawmidi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,13 @@ long snd_rawmidi_kernel_read(struct snd_rawmidi_substream *substream,
191191
long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream,
192192
const unsigned char *buf, long count);
193193

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+
194203
#endif /* __SOUND_RAWMIDI_H */

include/uapi/sound/asound.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ enum {
730730
#define SNDRV_RAWMIDI_INFO_UMP 0x00000008
731731
#define SNDRV_RAWMIDI_INFO_STREAM_INACTIVE 0x00000010
732732

733-
#define SNDRV_RAWMIDI_DEVICE_UNKNOWN -1
733+
#define SNDRV_RAWMIDI_DEVICE_UNKNOWN 0
734734

735735
struct snd_rawmidi_info {
736736
unsigned int device; /* RO/WR (control): device number */

sound/core/rawmidi.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,6 @@ int snd_rawmidi_init(struct snd_rawmidi *rmidi,
18371837
INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams);
18381838
INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams);
18391839
rmidi->info_flags = info_flags;
1840-
rmidi->tied_device = SNDRV_RAWMIDI_DEVICE_UNKNOWN;
18411840

18421841
if (id != NULL)
18431842
strscpy(rmidi->id, id, sizeof(rmidi->id));

sound/core/ump.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,8 +1382,7 @@ int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump,
13821382
ump_legacy_set_rawmidi_name(ump);
13831383
update_legacy_names(ump);
13841384

1385-
rmidi->tied_device = ump->core.device;
1386-
ump->core.tied_device = rmidi->device;
1385+
snd_rawmidi_tie_devices(rmidi, &ump->core);
13871386

13881387
ump_dbg(ump, "Created a legacy rawmidi #%d (%s)\n", device, id);
13891388
return 0;

0 commit comments

Comments
 (0)