aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2017-12-18 17:36:57 -0500
committerTakashi Iwai <tiwai@suse.de>2017-12-19 01:41:07 -0500
commit5a15f289ee87eaf33f13f08a4909ec99d837ec5f (patch)
tree27b5262477f3b9baf216e90fe12dca3d52a3d2be
parent9226665159f0367ad08bc7d5dd194aeadb90316f (diff)
ALSA: usb-audio: Fix the missing ctl name suffix at parsing SU
The commit 89b89d121ffc ("ALSA: usb-audio: Add check return value for usb_string()") added the check of the return value from snd_usb_copy_string_desc(), which is correct per se, but it introduced a regression. In the original code, either the "Clock Source", "Playback Source" or "Capture Source" suffix is added after the terminal string, while the commit changed it to add the suffix only when get_term_name() is failing. It ended up with an incorrect ctl name like "PCM" instead of "PCM Capture Source". Also, even the original code has a similar bug: when the ctl name is generated from snd_usb_copy_string_desc() for the given iSelector, it also doesn't put the suffix. This patch addresses these issues: the suffix is added always when no static mapping is found. Also the patch tries to put more comments and cleans up the if/else block for better readability in order to avoid the same pitfall again. Fixes: 89b89d121ffc ("ALSA: usb-audio: Add check return value for usb_string()") Reported-and-tested-by: Mauro Santos <registo.mailling@gmail.com> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--sound/usb/mixer.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index afc208e1c756..60ebc99ae323 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -2173,20 +2173,25 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid,
2173 kctl->private_value = (unsigned long)namelist; 2173 kctl->private_value = (unsigned long)namelist;
2174 kctl->private_free = usb_mixer_selector_elem_free; 2174 kctl->private_free = usb_mixer_selector_elem_free;
2175 2175
2176 nameid = uac_selector_unit_iSelector(desc); 2176 /* check the static mapping table at first */
2177 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); 2177 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name));
2178 if (len)
2179 ;
2180 else if (nameid)
2181 len = snd_usb_copy_string_desc(state, nameid, kctl->id.name,
2182 sizeof(kctl->id.name));
2183 else
2184 len = get_term_name(state, &state->oterm,
2185 kctl->id.name, sizeof(kctl->id.name), 0);
2186
2187 if (!len) { 2178 if (!len) {
2188 strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name)); 2179 /* no mapping ? */
2180 /* if iSelector is given, use it */
2181 nameid = uac_selector_unit_iSelector(desc);
2182 if (nameid)
2183 len = snd_usb_copy_string_desc(state, nameid,
2184 kctl->id.name,
2185 sizeof(kctl->id.name));
2186 /* ... or pick up the terminal name at next */
2187 if (!len)
2188 len = get_term_name(state, &state->oterm,
2189 kctl->id.name, sizeof(kctl->id.name), 0);
2190 /* ... or use the fixed string "USB" as the last resort */
2191 if (!len)
2192 strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name));
2189 2193
2194 /* and add the proper suffix */
2190 if (desc->bDescriptorSubtype == UAC2_CLOCK_SELECTOR) 2195 if (desc->bDescriptorSubtype == UAC2_CLOCK_SELECTOR)
2191 append_ctl_name(kctl, " Clock Source"); 2196 append_ctl_name(kctl, " Clock Source");
2192 else if ((state->oterm.type & 0xff00) == 0x0100) 2197 else if ((state->oterm.type & 0xff00) == 0x0100)