Skip to content

Commit

Permalink
ALSA: rawmidi: Make tied_device=0 as default / unknown
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Takashi Iwai committed Jan 14, 2025
1 parent 3784950 commit 3846699
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
9 changes: 9 additions & 0 deletions include/sound/rawmidi.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,13 @@ long snd_rawmidi_kernel_read(struct snd_rawmidi_substream *substream,
long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream,
const unsigned char *buf, long count);

/* set up the tied devices */
static inline void snd_rawmidi_tie_devices(struct snd_rawmidi *r1,
struct snd_rawmidi *r2)
{
/* tied_device field keeps the device+1 (so that 0 being unknown) */
r1->tied_device = r2->device + 1;
r2->tied_device = r1->device + 1;
}

#endif /* __SOUND_RAWMIDI_H */
2 changes: 1 addition & 1 deletion include/uapi/sound/asound.h
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ enum {
#define SNDRV_RAWMIDI_INFO_UMP 0x00000008
#define SNDRV_RAWMIDI_INFO_STREAM_INACTIVE 0x00000010

#define SNDRV_RAWMIDI_DEVICE_UNKNOWN -1
#define SNDRV_RAWMIDI_DEVICE_UNKNOWN 0

struct snd_rawmidi_info {
unsigned int device; /* RO/WR (control): device number */
Expand Down
1 change: 0 additions & 1 deletion sound/core/rawmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,6 @@ int snd_rawmidi_init(struct snd_rawmidi *rmidi,
INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams);
INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams);
rmidi->info_flags = info_flags;
rmidi->tied_device = SNDRV_RAWMIDI_DEVICE_UNKNOWN;

if (id != NULL)
strscpy(rmidi->id, id, sizeof(rmidi->id));
Expand Down
3 changes: 1 addition & 2 deletions sound/core/ump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1382,8 +1382,7 @@ int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump,
ump_legacy_set_rawmidi_name(ump);
update_legacy_names(ump);

rmidi->tied_device = ump->core.device;
ump->core.tied_device = rmidi->device;
snd_rawmidi_tie_devices(rmidi, &ump->core);

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

0 comments on commit 3846699

Please sign in to comment.