Received: by 10.223.185.116 with SMTP id b49csp6417403wrg; Wed, 28 Feb 2018 09:04:06 -0800 (PST) X-Google-Smtp-Source: AH8x224l4s4oZj+D/P5HLUlHvjrM1nacaBubPlM3V6fQWOfQNiUQQOAAU+KiiXpYR9lccxwQ2PUk X-Received: by 10.98.96.70 with SMTP id u67mr18615277pfb.66.1519837446370; Wed, 28 Feb 2018 09:04:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519837446; cv=none; d=google.com; s=arc-20160816; b=szU1gLEH5mSHrctuY3jB244MipuhRv7H4dcrTJUDiI4bQ82xbSLI+Ds+3HfwHUSicH 51BfpiirAtY6flEvhpT3IEinPqkan5DTpvAHfH34lhJ0tgAI+yyoZiQffURkRydedDRr /+5SiMuF7Q4VbcHEUj/ABr5X2OPP/JKjPdid2/pBTmGrW9+ToLVNBpmYCDKh/kxgN+9O NesOC+KDsw7hTfS8ffEaJSgjMN0k3DLOcjTf72ySaQ8ZnVCsFWen/fOVDuTQaandR0do foqYk89UajxgAI0HtcxXLeOB4fbi/EL7F+DgtXBBZdaGaPJf0napvtkuXTCxTSwgGrAV NquA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=Hg6/rF56nWCt67IdhepM+YaUqPAhwziLQ4TNT14XkL0=; b=po05i3M6vBesN84l9c5palZe31RjZ1Vaj54U9QGQEkxmJsKrRE/ezRbizx17rzVqqs 7ngY64SwIn84ai4TxZv+VEHjwvST0sJ2tMvHtDKSUsPCqJ8gxNJAEUqigIiaakF4uZ4k zpxT5iAVGCzvCsoRAwnlSbq6NOsKbzfArIogFQGBPzxa1ME1iJUDbmt+MlG5oW2eZa0N nJuEIQVI67HFYwAZ3qr4sZrzDS3nkIVM6fyqJfMZDRK8zt5x4R8/k500BgI2eMJkuaSI UaDyAq3Jn29QtVPMEuL51dq3W5Du1dLoIda6ZximB/1fJgKaj/RNxOyjKR6MU9I/P3Nc nDNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r6-v6si1515561pls.13.2018.02.28.09.03.31; Wed, 28 Feb 2018 09:04:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933856AbeB1RBw (ORCPT + 99 others); Wed, 28 Feb 2018 12:01:52 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34369 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932696AbeB1PwE (ORCPT ); Wed, 28 Feb 2018 10:52:04 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Yi-0006Xg-8j; Wed, 28 Feb 2018 15:22:20 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yg-00006x-VF; Wed, 28 Feb 2018 15:22:18 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Takashi Iwai" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 124/254] ALSA: usb-audio: Fix the missing ctl name suffix at parsing SU In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai commit 5a15f289ee87eaf33f13f08a4909ec99d837ec5f upstream. 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 Signed-off-by: Takashi Iwai Signed-off-by: Ben Hutchings --- sound/usb/mixer.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c @@ -2095,20 +2095,25 @@ static int parse_audio_selector_unit(str kctl->private_value = (unsigned long)namelist; kctl->private_free = usb_mixer_selector_elem_free; - nameid = uac_selector_unit_iSelector(desc); + /* check the static mapping table at first */ len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); - if (len) - ; - else if (nameid) - len = snd_usb_copy_string_desc(state, nameid, kctl->id.name, - sizeof(kctl->id.name)); - else - len = get_term_name(state, &state->oterm, - kctl->id.name, sizeof(kctl->id.name), 0); - if (!len) { - strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name)); + /* no mapping ? */ + /* if iSelector is given, use it */ + nameid = uac_selector_unit_iSelector(desc); + if (nameid) + len = snd_usb_copy_string_desc(state, nameid, + kctl->id.name, + sizeof(kctl->id.name)); + /* ... or pick up the terminal name at next */ + if (!len) + len = get_term_name(state, &state->oterm, + kctl->id.name, sizeof(kctl->id.name), 0); + /* ... or use the fixed string "USB" as the last resort */ + if (!len) + strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name)); + /* and add the proper suffix */ if (desc->bDescriptorSubtype == UAC2_CLOCK_SELECTOR) append_ctl_name(kctl, " Clock Source"); else if ((state->oterm.type & 0xff00) == 0x0100)