Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1371767imu; Wed, 16 Jan 2019 18:23:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN4pgp9BU8boC0vI2hfClubGmdxIA342V9YlfnyT+FEZ9lDiooLxuZlBqi5Nrj8qcWTprk6g X-Received: by 2002:a17:902:6948:: with SMTP id k8mr12987196plt.2.1547691805486; Wed, 16 Jan 2019 18:23:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547691805; cv=none; d=google.com; s=arc-20160816; b=rKNK/JEV43SYfHutBluVb3mOpZFwPvPj/3S9iYZE2XSXmGtLvBm+i+V/szsjRQBvFZ SNZ1yGcUsI7B+vlGRzcQT9akZCd9wKwQ6T4ZDadaH7N429HLwEAsipgGBJx1NIQi2kse xblK7jq/Il324ocTQSGoS7snuZFJgUbrD3E9WFqe1H8N9fgjibD4q828kMGIRD4V5e8I VS9KfJkb60K6zReOE9vS6fOSvECRWh7+VDwAbOuGdEZqDXcswJ8PMhY6AkSkv2Hf+5GA 9C39i502PJVMGIT0FRF+tSx2b42Uqs+UFWYsD7BHz8MG4rb0ITZKvQ2+v9n6/zznP3d0 E4eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :dlp-reaction:dlp-version:dlp-product:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=+EosuMZy5G+oa05eM4VQKY5XyMjFEWdbdLEWMIh99bQ=; b=R5yz6aIa6CGKpTaF8c1N3HDS7wb0oAu/WSXniRfDchSJztC2Ars7I+hymbZNlkV5zB DJrG24MaXn04HEFrFONDTFPl99jGgZOc0KlyD+wDZXnemmBSfMP1e4MU3YS/xKIVi9sW wwc451QKf8Jb73lwbFWmA+TKq858TZzItL3aNbjlESb5+fNh0H9MSZJYQ2E/3orIxoVf txuHrerMD5xLwV+LigY3jl3pkARpwDJQtJlHFokzKFL+hqxm+pHKZ5HJ7hNwa8TzDX58 6fsezcsFUdleoOGF9xXsgNyYRtR3p+0KsAWAxBOa0J4JaZ5C6man5+xYfJ1BrJKQZbim CgSQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i9si243298plb.35.2019.01.16.18.23.08; Wed, 16 Jan 2019 18:23:25 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731814AbfAPEYi convert rfc822-to-8bit (ORCPT + 99 others); Tue, 15 Jan 2019 23:24:38 -0500 Received: from mga18.intel.com ([134.134.136.126]:50645 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729203AbfAPEYi (ORCPT ); Tue, 15 Jan 2019 23:24:38 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jan 2019 20:24:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,484,1539673200"; d="scan'208";a="126396932" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga002.jf.intel.com with ESMTP; 15 Jan 2019 20:24:37 -0800 Received: from fmsmsx158.amr.corp.intel.com (10.18.116.75) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 15 Jan 2019 20:24:37 -0800 Received: from bgsmsx151.gar.corp.intel.com (10.224.48.42) by fmsmsx158.amr.corp.intel.com (10.18.116.75) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 15 Jan 2019 20:24:37 -0800 Received: from bgsmsx104.gar.corp.intel.com ([169.254.5.227]) by BGSMSX151.gar.corp.intel.com ([169.254.3.74]) with mapi id 14.03.0415.000; Wed, 16 Jan 2019 09:54:30 +0530 From: "Gopal, Saranya" To: Nikolay Yakimov , Greg Kroah-Hartman CC: "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] USB: Fix configuration selection issues introduced in v4.20.0 Thread-Topic: [PATCH] USB: Fix configuration selection issues introduced in v4.20.0 Thread-Index: AQHUrO1tcNtp2QCCK0m5HD3lqJDdwKWxQnqw Date: Wed, 16 Jan 2019 04:24:30 +0000 Message-ID: References: <20190115161354.6806-1-root@livid.pp.ru> In-Reply-To: <20190115161354.6806-1-root@livid.pp.ru> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNDg5YjYxOTItMjkwMC00YjZkLWI5ZDctYWM2ODk3YjRlNWRmIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiblZDTDZzNGE3WWs4RTI5Q3d2ZHFqQUZ2dnhRMGpqcEhTNlh2XC9DTmlLNUlVNnNCb3pxbFJNcG00ZFRZbk5QWkEifQ== x-originating-ip: [10.223.10.10] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Yakimov, As per UAC3 configuration, the first configuration will always be backward-compatible. So, there cannot be any UAC3-compatible device which has first configuration as UAC3. And secondly, the commit ff2a8c532c14 does not break the pre-existing logic. I also thought so much about moving the code above Ethernet check while preparing ff2a8c532c14. But, then, it doesn't break the existing logic and so decided against moving it. Thanks, Saranya > -----Original Message----- > From: Nikolay Yakimov [mailto:root@livid.pp.ru] > Sent: Tuesday, January 15, 2019 9:44 PM > To: Greg Kroah-Hartman > Cc: Nikolay Yakimov ; Gopal, Saranya > ; linux-usb@vger.kernel.org; linux- > kernel@vger.kernel.org > Subject: [PATCH] USB: Fix configuration selection issues introduced in v4.20.0 > > 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