Skip to content

Commit 85e8d66

Browse files
committed
ALSA: ump: Copy safe string name to rawmidi
The UMP helper didn't set up the rawmidi name string by itself but left it to the driver. But since the only user (USB MIDI2 driver) picks up the UMP info name string to the rawmidi name as default, it's better to set up in the UMP core side. Meanwhile, UMP receives the EP name string from the device, and it might contain garbage letters. We should purify the string to be usable for the kernel as done previously for UMP Group names. This implements the copy of the UMP info name string into the rawmidi name at the creation of UMP EP object in a safe way to strip the non-ASCII or non-printable characters. Also, change the reference from the legacy rawmidi and other places to rawmidi name field instead of ump info; this assures the sane strings. Signed-off-by: Takashi Iwai <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent e3f035e commit 85e8d66

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

sound/core/ump.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,13 @@ static int ump_handle_device_info_msg(struct snd_ump_endpoint *ump,
740740
return 1; /* finished */
741741
}
742742

743+
/* set up the core rawmidi name from UMP EP name string */
744+
static void ump_set_rawmidi_name(struct snd_ump_endpoint *ump)
745+
{
746+
safe_copy_string(ump->core.name, sizeof(ump->core.name),
747+
ump->info.name, sizeof(ump->info.name));
748+
}
749+
743750
/* handle EP name stream message; update the UMP name string */
744751
static int ump_handle_ep_name_msg(struct snd_ump_endpoint *ump,
745752
const union snd_ump_stream_msg *buf)
@@ -1067,6 +1074,8 @@ int snd_ump_parse_endpoint(struct snd_ump_endpoint *ump)
10671074
if (err < 0)
10681075
ump_dbg(ump, "Unable to get UMP EP name string\n");
10691076

1077+
ump_set_rawmidi_name(ump);
1078+
10701079
/* Request Endpoint Product ID */
10711080
err = ump_req_msg(ump, msg, UMP_STREAM_MSG_REQUEST_PRODUCT_ID,
10721081
UMP_STREAM_MSG_STATUS_PRODUCT_ID);
@@ -1283,7 +1292,7 @@ static void update_legacy_substreams(struct snd_ump_endpoint *ump,
12831292
idx = ump->legacy_mapping[s->number];
12841293
name = ump->groups[idx].name;
12851294
if (!*name)
1286-
name = ump->info.name;
1295+
name = ump->core.name;
12871296
scnprintf(s->name, sizeof(s->name), "Group %d (%.16s)%s",
12881297
idx + 1, name,
12891298
ump->groups[idx].active ? "" : " [Inactive]");
@@ -1330,7 +1339,7 @@ int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump,
13301339
snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
13311340
&snd_ump_legacy_output_ops);
13321341
snprintf(rmidi->name, sizeof(rmidi->name), "%.68s (MIDI 1.0)",
1333-
ump->info.name);
1342+
ump->core.name);
13341343
rmidi->info_flags = ump->core.info_flags & ~SNDRV_RAWMIDI_INFO_UMP;
13351344
rmidi->ops = &snd_ump_legacy_ops;
13361345
rmidi->private_data = ump;

0 commit comments

Comments
 (0)