Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5062950imu; Tue, 15 Jan 2019 10:30:15 -0800 (PST) X-Google-Smtp-Source: ALg8bN4pwut53vYqJUpzN8oNkxirmFvpOBuWGkGS0guFkIhbXOzV/t6YEDJMpwpbkbYp6Wv32rAk X-Received: by 2002:a17:902:b18b:: with SMTP id s11mr5465106plr.56.1547577015711; Tue, 15 Jan 2019 10:30:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547577015; cv=none; d=google.com; s=arc-20160816; b=OII8X8y7nbxq9ojM6Mx26yluGKczWrFEWnQvHkCjXYuaxSekMSKLR4+cAWddjNAfwX T0O26ozOD7nepBIHyxRiBDSFRTUcTCBnKmK5F1qp19YaauBtDpcC8iJnDmtOw5wTLJBh 6c/I9WDYHV1nNlajctw4mUlY1d1coFMg1TCKivL9jea9uAkkiHVU2hToEI+blVtfJ0R5 CphAIQNSdyx+7CiCFNARYKBH7BSMPmqnPAniqGccBCCqsY3hILne0/SFnmlJVq/A5shB OFcC0hXzEQSAQ4zcJwhIWHzP2RKFrEo0gS4Ig5DYhoPHLJdiX2Dgy7QI6SZEUjvW1+oH xpVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3TB4Cm8e2Fl64TYPTWBUE8YQgabZLtz0Yy0eRN0D9Nc=; b=vvBYYi4hN3eD5+y7a8k4rYWqI6meUJvpNT32M8Ewgp6lbyF/19r9Uxhn01DRG12XUR 7TVXT3tZnInC45TgSnNwu4oEt1ZWc32kty08KaDu/o82h4WL7NG+UfLR6X8oruG6HWq3 eoviBtZQNhvLZ14yTiGf2kNpNha0RxYo1R4zb7m0g1KLH10Y//jaxEEbV20Wn2B6ndrs Xh2C0Df4m/cnrGkle+vyMIf0j1+MihQklSj7QpfuXIlXFtNbjU8dQvdK0ccc4JsBKEs/ kiKS0KI5JRlW6IsemfVo7vnqsl2qx67r7+9JvDJJzpOq5TGrtDcalWx0rWPt/Jm7r+YU Adew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@livid.pp.ru header.s=google header.b=jBqouk0M; 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 a6si3906932pfa.227.2019.01.15.10.29.59; Tue, 15 Jan 2019 10:30:15 -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; dkim=pass header.i=@livid.pp.ru header.s=google header.b=jBqouk0M; 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 S1731396AbfAOQO1 (ORCPT + 99 others); Tue, 15 Jan 2019 11:14:27 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:33949 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729543AbfAOQO0 (ORCPT ); Tue, 15 Jan 2019 11:14:26 -0500 Received: by mail-ed1-f66.google.com with SMTP id b3so3020763ede.1 for ; Tue, 15 Jan 2019 08:14:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=livid.pp.ru; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3TB4Cm8e2Fl64TYPTWBUE8YQgabZLtz0Yy0eRN0D9Nc=; b=jBqouk0MMQ0gHtVJrZtiRjDJ4+EEMV0st2D2YWwkMurTAQwC/Onm8LZf43WQLvhWuq KW4K1t05HKETjp3XdxHV+d93AhOIjVFOwDeob375sSnZ2AjLpchUN84xPMOPPSnw/EsN YcOVTJN/jgTvW/51VLt+NxdWU26Ec6EB0AhVI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3TB4Cm8e2Fl64TYPTWBUE8YQgabZLtz0Yy0eRN0D9Nc=; b=jiCRS/ZTMaT/YesYHwnhLhAHTO4DPZRnOewTtsD7gKwKWHhP72Gf0Y8VIrnrb8F4MI waXAJLSv0qMQU8vfN7DY5qoRm1UGgnxvFp/efptD9jKy9aSczxmK1dniS5z5yhteF1j7 t1DXjo4DPHzIcpJMApPYdwue/kIRjKV/OdOOeT+BRCdlLu//QwNRGNIvhLPqyYiUexI6 gLMN1RBjVd0VcvfXGLsOPJkyL4IPwcd7qGPu/3j/L0OWjB18YIlFh1YhOzzU7jnXGble Zs6+WKs16donBqV/mr5qPinWaRFhFBzfk+wiwSanCsYssoR4+hJZKmmyPKOAkz1XNKfb rTEg== X-Gm-Message-State: AJcUukecO8V8IMFT0TFXGLesoXLaXibirCaneFyzxIqWQZgEOlGquGF5 iQurtLxEE477P1tIH7hIAbIoSQ== X-Received: by 2002:a17:906:351a:: with SMTP id r26-v6mr3546188eja.193.1547568864264; Tue, 15 Jan 2019 08:14:24 -0800 (PST) Received: from livid.lan ([2001:470:71:c0c::d0e5:a55]) by smtp.gmail.com with ESMTPSA id r51sm5029101eda.64.2019.01.15.08.14.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Jan 2019 08:14:23 -0800 (PST) From: Nikolay Yakimov To: Greg Kroah-Hartman Cc: Nikolay Yakimov , Saranya Gopal , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] USB: Fix configuration selection issues introduced in v4.20.0 Date: Tue, 15 Jan 2019 19:13:54 +0300 Message-Id: <20190115161354.6806-1-root@livid.pp.ru> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit f13912d3f014a introduced changes to the usb_choose_configuration function to better support USB Audio UAC3-compatible devices. However, there are a few problems with this patch. First of all, it adds new "if" clauses in the middle of an existing "if"/"else if" tree, which obviously breaks pre-existing logic. Secondly, since it continues iterating over configurations in one of the branches, other code in the loop can choose an unintended configuration. Finally, if an audio device's first configuration is UAC3-compatible, and there are multiple UAC3 configurations, the second one would be chosen, due to the first configuration never being checked for UAC3-compatibility. Commit ff2a8c532c14 tries to fix the second issue, but it goes about it in a somewhat unnecessarily convoluted way, in my opinion, and does nothing to fix the first or the last one. This patch tries to rectify problems described by essentially rewriting code introduced in f13912d3f014a. Notice the code was moved to *before* the "if"/"else if" tree. Signed-off-by: Nikolay Yakimov --- drivers/usb/core/generic.c | 44 ++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c index f713cecc1f41..1ac9c1e5f773 100644 --- a/drivers/usb/core/generic.c +++ b/drivers/usb/core/generic.c @@ -118,6 +118,31 @@ int usb_choose_configuration(struct usb_device *udev) continue; } + /* + * Select first configuration as default for audio so that + * devices that don't comply with UAC3 protocol are supported. + * But, still iterate through other configurations and + * select UAC3 compliant config if present. + */ + if (desc && is_audio(desc)) { + /* Always prefer the first found UAC3 config */ + if (is_uac3_config(desc)) { + best = c; + break; + } + + /* If there is no UAC3 config, prefer the first config */ + else if (i == 0) + best = c; + + /* Unconditional continue, because the rest of the code + * in the loop is irrelevant for audio devices, and + * because it can reassign best, which for audio devices + * we don't want. + */ + continue; + } + /* When the first config's first interface is one of Microsoft's * pet nonstandard Ethernet-over-USB protocols, ignore it unless * this kernel has enabled the necessary host side driver. @@ -132,25 +157,6 @@ int usb_choose_configuration(struct usb_device *udev) #endif } - /* - * Select first configuration as default for audio so that - * devices that don't comply with UAC3 protocol are supported. - * But, still iterate through other configurations and - * select UAC3 compliant config if present. - */ - if (i == 0 && num_configs > 1 && desc && is_audio(desc)) { - best = c; - continue; - } - - if (i > 0 && desc && is_audio(desc)) { - if (is_uac3_config(desc)) { - best = c; - break; - } - continue; - } - /* From the remaining configs, choose the first one whose * first interface is for a non-vendor-specific class. * Reason: Linux is more likely to have a class driver -- 2.20.1