Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1279547imu; Wed, 16 Jan 2019 16:17:18 -0800 (PST) X-Google-Smtp-Source: ALg8bN4RDqJyb+GMlaNByHfWLVTPy59tPhI4T3YS7rl3VLrWyPP4l1+xYnrfreA3B7vhZHgWGb1H X-Received: by 2002:a63:e950:: with SMTP id q16mr11476476pgj.138.1547684238715; Wed, 16 Jan 2019 16:17:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547684238; cv=none; d=google.com; s=arc-20160816; b=gzCBBkK3lN9cokJ1TEN1WSZDQ1uOvE9rLQNbC3cXXqNsbLrUmP51M6GF4sJgTCyjKd 65ss8/88m7NSf3gRjl4gT198Nr/VIZ6gZ96Np7fJFg0X18EvXUCOP4/J9RPvLaE/z1m+ x7GhuXwinBV4ScTMhSOdvad+HDArDqa1cy+NmBxMirt9EeqHqU324sezimTRPDXvj5Of 0MnIk5hl3Evku/dHoKpVWBw9vAZxqHQbJeQVvgh4SodSnZbzR5DI+vsLznrFkrzilzro QckcsqpmMPnXZFFwtf4ZXKf5z9agrkQN84FhzVhBcEYK408y1eFiDXRcqUzIHx7hY9j0 7MSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=6O4Ox5t7gZr3BNqT4wDqOavrgJWtBvGiG11JwN1bp8U=; b=U5l9oZYUjKWQGd4O7avlQJqAltaypy9Fv+5AJuTAs0O4LUOzI5V4bFfXeQEQSUia/n WEbV0iq3NSmi7RhA3aSGeQ9Ova2Z/04ktQG8Y9vU7/mSD5d0XJbJBbpuFA77sfrvqIGo 4PKzJ5I2dtS0D0eUwaASP9S81g/Eqc7f6OEQRKO2WoPMjlzu42X7NBz3ugZGiGw3cNOE m6IoclsHjgodr9SzPJpOzYO9ksMudD9Int3pEE4Jcw0HpybtEeeU04CLRE/QtumBlq43 +uLKrwISWAVRDVQKw8a9DJ0DEAmTZe9aA3CJ0tdmStpTzMyxYfvXqn9udeF9XxfC5Ikv TCKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@livid.pp.ru header.s=google header.b="ChX+/8+g"; 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 n13si6870886pgp.307.2019.01.16.16.17.00; Wed, 16 Jan 2019 16:17:18 -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="ChX+/8+g"; 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 S1730460AbfAPTNh (ORCPT + 99 others); Wed, 16 Jan 2019 14:13:37 -0500 Received: from mail-qt1-f195.google.com ([209.85.160.195]:40922 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730403AbfAPTNh (ORCPT ); Wed, 16 Jan 2019 14:13:37 -0500 Received: by mail-qt1-f195.google.com with SMTP id k12so8486384qtf.7 for ; Wed, 16 Jan 2019 11:13:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=livid.pp.ru; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6O4Ox5t7gZr3BNqT4wDqOavrgJWtBvGiG11JwN1bp8U=; b=ChX+/8+gdUAK9lq7XLx38pORNXW1+48u/QBXWKDG5nthXpFL2mJFJTRMQSLjiVWj02 MVD2A8mMtCd59PPFUFqjF03EFZHHqACyiqAXnecVASxM4KizPrshaGrIb0yzuiXzgx91 tHv2Cobi39d+OomOUJ/gv4+fQESevk50q2zUk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6O4Ox5t7gZr3BNqT4wDqOavrgJWtBvGiG11JwN1bp8U=; b=sjYhNJ6Arc/n3MKyNLaY/FtMbNSQZfffhw1NaqCxdeL6CS6r/oy3jN2fLhdttynQnJ UMncpwUHNLq8hZsU5H4BeZHR821vlq7tbF+iDDPcwIZwvXW6GrWWE1mDv0yYiJLgYfiy PDBD5AgdujKNedA8cgtb2Y3JMsdjbIWDkjXib06gRp4WT0puBoXl1vXZqpKOxP09r9tp 4V7Gf5VhBPgUww23o+UsHucMWaHXPy5pcWt9erCOyrCEyTklqDEWQ8tqg4gU15EfwXvF NbrYfCct28qiw9LSsONSpLLlseqmxXdCjpWEiLMjSupeXHyX4NPrFcovFoMy2XZcWo3A sd/w== X-Gm-Message-State: AJcUukcA6wYwmtwBU2s/HYGJJTkvY1Vk1ehMLKbb0GwBSxlL3nk6uLKC W03eVKhKLCutLUJvMmcgHaTl1aXN5r9a+mpTQtVNxg== X-Received: by 2002:ad4:410c:: with SMTP id i12mr8237687qvp.219.1547666015583; Wed, 16 Jan 2019 11:13:35 -0800 (PST) MIME-Version: 1.0 References: <20190115161354.6806-1-root@livid.pp.ru> In-Reply-To: From: Nikolay Yakimov Date: Wed, 16 Jan 2019 22:13:24 +0300 Message-ID: Subject: Re: [PATCH] USB: Fix configuration selection issues introduced in v4.20.0 To: "Gopal, Saranya" Cc: Greg Kroah-Hartman , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 16 Jan 2019 at 07:24, Gopal, Saranya wrote: > > 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. Thanks for the clarification. I would argue though that not all devices might adhere to the specification, so it's still probably a good idea to check all configurations "just in case". I will not press this point though. > 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. It does seem to change the logic for RNDIS devices with multiple configurations when RNDIS kernel module is enabled. Consider an RNDIS device with multiple configurations (num_configs > 1) Before f13912d3f014a, the following sequence would be executed: 1. i == 0. if (i == 0 && num_configs > 1 && desc && (is_rndis(desc) || is_activesync(desc))) { best = c; } else ... The condition is true, so this branch is executed. The first configuration is selected. Since it's the last condition (all the remaining code in the loop body is in the else branch), the loop will continue onto the next iteration. 2. i == 1. if (i == 0 && num_configs > 1 && desc && (is_rndis(desc) || is_activesync(desc))) { ... } else if (udev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC && (desc && desc->bInterfaceClass != USB_CLASS_VENDOR_SPEC)) { best = c; break; } else ... If the second configuration is not vendor-specific, the first "else if" branch would be executed, and the second configuration is selected. The loop is exited on break. After ff2a8c532c14, the following sequence would be executed: 1. i == 0. if (i == 0 && num_configs > 1 && desc && (is_rndis(desc) || is_activesync(desc))) { best = c; } The condition is true, so this branch is executed. The first configuration is selected, but the loop body continues execution. 2. Still i == 0. if (i == 0 && num_configs > 1 && desc && is_audio(desc)) { ... } A redundant check is preformed to check if the device is an audio device. We already know it isn't. 3. Still i == 0. if (i > 0 && desc && is_audio(desc)) { ... } else ... A redundant check is preformed to check if (i > 0). We already know it isn't. 4. Still i == 0. else if (udev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC && (desc && desc->bInterfaceClass != USB_CLASS_VENDOR_SPEC)) { best = c; break; } else ... The first "else if" condition is checked. Unless bDeviceClass is USB_CLASS_VENDOR_SPEC (correct me if I'm wrong, but in most cases I think it wouldn't be), that condition evaluates as true. The configuration is selected (redundantly), and the loop is exited on break. The result is this: Before f13912d3f014a, if an RNDIS device has non-vendor-specific configurations after the first one, that one would be selected. After ff2a8c532c14, the first configuration would always be selected for RNDIS devices. Besides, there are several redundant checks in this case, which is, if nothing else, confusing. Hopefully I've explained my point clearly enough. > > Thanks, > Saranya