ALSA: usb-audio: Attach legacy rawmidi after probing all UMP EPs
authorTakashi Iwai <tiwai@suse.de>
Thu, 24 Aug 2023 07:51:05 +0000 (09:51 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 24 Aug 2023 08:03:15 +0000 (10:03 +0200)
The legacy rawmidi devices are the shadows of the main UMP devices,
hence it's better to initialize them after all UMP Endpoints are
parsed.  Then, at the moment the legacy rawmidi is created, we already
know the static flag or the proper EP name string, and we can fill
those information at UMP core side instead of fiddling the attributes
at a later point.

Fixes: ec362b63c4b5 ("ALSA: usb-audio: Enable the legacy raw MIDI support")
Link: https://lore.kernel.org/r/20230824075108.29958-2-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/ump.c
sound/usb/midi2.c

index fbe2892..b72b6dc 100644 (file)
@@ -1150,6 +1150,8 @@ int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump,
        if (output)
                snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
                                    &snd_ump_legacy_output_ops);
+       snprintf(rmidi->name, sizeof(rmidi->name), "%s (MIDI 1.0)",
+                ump->info.name);
        rmidi->info_flags = ump->core.info_flags & ~SNDRV_RAWMIDI_INFO_UMP;
        rmidi->ops = &snd_ump_legacy_ops;
        rmidi->private_data = ump;
index ee28357..a27e244 100644 (file)
@@ -990,7 +990,7 @@ static int parse_midi_2_0(struct snd_usb_midi2_interface *umidi)
                }
        }
 
-       return attach_legacy_rawmidi(umidi);
+       return 0;
 }
 
 /* is the given interface for MIDI 2.0? */
@@ -1059,12 +1059,6 @@ static void set_fallback_rawmidi_names(struct snd_usb_midi2_interface *umidi)
                        usb_string(dev, dev->descriptor.iSerialNumber,
                                   ump->info.product_id,
                                   sizeof(ump->info.product_id));
-#if IS_ENABLED(CONFIG_SND_UMP_LEGACY_RAWMIDI)
-               if (ump->legacy_rmidi && !*ump->legacy_rmidi->name)
-                       snprintf(ump->legacy_rmidi->name,
-                                sizeof(ump->legacy_rmidi->name),
-                                "%s (MIDI 1.0)", ump->info.name);
-#endif
        }
 }
 
@@ -1157,6 +1151,13 @@ int snd_usb_midi_v2_create(struct snd_usb_audio *chip,
        }
 
        set_fallback_rawmidi_names(umidi);
+
+       err = attach_legacy_rawmidi(umidi);
+       if (err < 0) {
+               usb_audio_err(chip, "Failed to create legacy rawmidi\n");
+               goto error;
+       }
+
        return 0;
 
  error: