From patchwork Mon Sep 21 13:59:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11789913 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA80F139A for ; Mon, 21 Sep 2020 14:00:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C947E20B1F for ; Mon, 21 Sep 2020 14:00:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600696806; bh=zvcSKdka8MWJDFF0L4+TxqQovqXBODY1v6/sOJYC9yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=zFvnTB3WjuK2/jai/1D6HhIHDJHh53/OuJQeOQ78OlQ6/vmicUpCh85BQbsf1AOT5 Zu3rRoMXedNS7ITO9ItY+HFluKP8USxyAxuiseEiWWfuhs5t77NX4uxnpa8CX78lSR CUYj9cda56/F5TNvhhzRxx2jcP//V1HKOuhXCph4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727369AbgIUOAF (ORCPT ); Mon, 21 Sep 2020 10:00:05 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:40286 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727263AbgIUOAF (ORCPT ); Mon, 21 Sep 2020 10:00:05 -0400 Received: by mail-lf1-f66.google.com with SMTP id m5so14129333lfp.7 for ; Mon, 21 Sep 2020 07:00:03 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=QeNREgn/VBFyeE24M7SC8hPxyEUzwzXz3H+WzHOfyA8=; b=VaWg0KccWh2iTrvGn3X2EsuHqbEM7OMPgKKBOyHAOYgnaNr39/6hGGeRzW4MB8+urq oL+kZOFkPRDNN0C/oHNOkrAODSCDC1JNbFZ2FemG0ZItb6KPJTIOO9lCyPYTCHaYZskd B2LZLe6CS/S2uF42gS8uUv2fVs1IdA+QwYnljVg8d5nDSRtmJXtqQvvjBtXJAs0DdmgT krpwN2gCByVX30fDUSLDWdr/QPBwLPr3kP0iqdboiT8MOBrUCn6DAas5qcUppCvzOwax 7HJjIuVaZh+AZvDlqglZHFlxPrRhUf0Ckiho0tNdTdKuBSkUwVvowPgmpvCyHLyk0Ysi KDfA== X-Gm-Message-State: AOAM530OgEtCwwBQIIbpRGnARORDUZSUP85NPwXRhLLityJdcCEwdGY0 91YKKvK7edHXvOq764Jiwxs= X-Google-Smtp-Source: ABdhPJyh55m81LxK+3KDLEWRsL2Kcu587mqoByGkpYzlEOYWzN0SGP6JbwghNNl7WHwUWL+sqLz8xw== X-Received: by 2002:a19:521a:: with SMTP id m26mr35819lfb.133.1600696802810; Mon, 21 Sep 2020 07:00:02 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id y21sm2728739ljk.110.2020.09.21.07.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 07:00:01 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kKMME-0006Go-WC; Mon, 21 Sep 2020 15:59:55 +0200 From: Johan Hovold To: Oliver Neukum Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, Daniel Caujolle-Bert , Johan Hovold Subject: [PATCH v2 1/4] Revert "cdc-acm: hardening against malicious devices" Date: Mon, 21 Sep 2020 15:59:48 +0200 Message-Id: <20200921135951.24045-2-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200921135951.24045-1-johan@kernel.org> References: <20200921135951.24045-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This reverts commit 2ad9d544f2497a7bf239c34bd2b86fd19683dbb5. Drop bogus sanity check; an interface in the active configuration will always have a current altsetting assigned by USB core. Signed-off-by: Johan Hovold --- drivers/usb/class/cdc-acm.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 7f6f3ab5b8a6..e28ac640ff9c 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -1196,9 +1196,6 @@ static int acm_probe(struct usb_interface *intf, return -EINVAL; } - if (!intf->cur_altsetting) - return -EINVAL; - if (!buflen) { if (intf->cur_altsetting->endpoint && intf->cur_altsetting->endpoint->extralen && @@ -1252,8 +1249,6 @@ static int acm_probe(struct usb_interface *intf, dev_dbg(&intf->dev, "no interfaces\n"); return -ENODEV; } - if (!data_interface->cur_altsetting || !control_interface->cur_altsetting) - return -ENODEV; if (data_intf_num != call_intf_num) dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n"); From patchwork Mon Sep 21 13:59:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11789911 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 52881112C for ; Mon, 21 Sep 2020 14:00:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B1CE21D91 for ; Mon, 21 Sep 2020 14:00:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600696806; bh=0nVXFxKlv3B/GshEQOcN9O2mcYuufyoFZnV3PZOywDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Krz5CgBvjIZfxZS6vfyMI+PVtiFbup77N+df07wm1I9r1VwKMZB1V9x892wv9X+DK 3YIdIL4ctdzSVPJHb2oaDzfEPkyMWLHq/inCiKBWr20DdGCrgpg8wZHK+gbIE/J20j YgpHKkvMo6FxgoETqUbk6rdQyF5D47ZmOCDMr3Qs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727365AbgIUOAF (ORCPT ); Mon, 21 Sep 2020 10:00:05 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:40367 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727212AbgIUOAE (ORCPT ); Mon, 21 Sep 2020 10:00:04 -0400 Received: by mail-lj1-f195.google.com with SMTP id s205so11170317lja.7; Mon, 21 Sep 2020 07:00:03 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hb+hvNgCGvB638VQzdE3NIGwCfs5oVJCLR3se4p/iOQ=; b=mmArRY58tz1JUoF4Mt13TyuEU2tR1XntFGnzjmQZIURnM8V4zoV+WGF4Go2XSqQe6f IKc40KM285evvj9AiLc66SixWYy5Fb0rqiwyEKe9nYSqvH8NKx9+VxGl9h8RzXYqHB95 J0L5K4WiVm0VUo7tarqlkVaSnKdRJGEZUi3/F1WbbAjUOq1siiNlGn71SjBPpjqmmSn7 n0cbYDN7sMVrMj6y8TgvTfdjBvnXc3rGXCXSz4gUq4BdxdsmwEp17jBPl4Hiuoy74EMp 8QFwGpZaG6bCMc3gdx9CRQl4TbMZiZ8aCC5qEkTOKYvOz1iAhfDUFBCAKFQHNAgVXt+L 5dLw== X-Gm-Message-State: AOAM530RPtuzKJjdOevWz0D+fUvTMpq/Zh/GsJVxNqlkK5sKeHYhs+gd aFHur82lGooDK3R3+pzJKfE= X-Google-Smtp-Source: ABdhPJz7LguBTd+8s7pivgoffUS7JzHCqg1FrpvAy9NmuriFUwh+MTpgAq7UPuAEvXTmBIZ/FLMscg== X-Received: by 2002:a2e:7215:: with SMTP id n21mr16504713ljc.438.1600696801854; Mon, 21 Sep 2020 07:00:01 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id k205sm2594711lfk.19.2020.09.21.07.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 07:00:01 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kKMMF-0006Gu-2Q; Mon, 21 Sep 2020 15:59:55 +0200 From: Johan Hovold To: Oliver Neukum Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, Daniel Caujolle-Bert , Johan Hovold , stable@vger.kernel.org Subject: [PATCH v2 2/4] USB: cdc-acm: handle broken union descriptors Date: Mon, 21 Sep 2020 15:59:49 +0200 Message-Id: <20200921135951.24045-3-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200921135951.24045-1-johan@kernel.org> References: <20200921135951.24045-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Handle broken union functional descriptors where the master-interface doesn't exist or where its class is of neither Communication or Data type (as required by the specification) by falling back to "combined-interface" probing. Note that this still allows for handling union descriptors with switched interfaces. This specifically makes the Whistler radio scanners TRX series devices work with the driver without adding further quirks to the device-id table. Link: https://lore.kernel.org/r/5f4ca4f8.1c69fb81.a4487.0f5f@mx.google.com Reported-by: Daniel Caujolle-Bert Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold Tested-by: Daniel Caujolle-Bert --- drivers/usb/class/cdc-acm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index e28ac640ff9c..f42ade505569 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -1240,9 +1240,21 @@ static int acm_probe(struct usb_interface *intf, } } } else { + int class = -1; + data_intf_num = union_header->bSlaveInterface0; control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); data_interface = usb_ifnum_to_if(usb_dev, data_intf_num); + + if (control_interface) + class = control_interface->cur_altsetting->desc.bInterfaceClass; + + if (class != USB_CLASS_COMM && class != USB_CLASS_CDC_DATA) { + dev_dbg(&intf->dev, "Broken union descriptor, assuming single interface\n"); + combined_interfaces = 1; + control_interface = data_interface = intf; + goto look_for_collapsed_interface; + } } if (!control_interface || !data_interface) { From patchwork Mon Sep 21 13:59:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11789909 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B9E3C6CA for ; Mon, 21 Sep 2020 14:00:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1262221E2 for ; Mon, 21 Sep 2020 14:00:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600696805; bh=GvpEeSb7mpkmWB2J4raM+MVjc/feP9t9P45xhH5FBI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=d65H9Cj1JyZyno1igHjRQXproXjJXdORH4b6wuos4VpIVDaPAyvSyypvL1oq+Dzhd oLcwo7EU5nRYvN9vqohex9mfOpZmhFPEIuDmJI//XolgvG9wQfQmSfvYqLeaKmx9kN DCjl69FmQlud/pyF3/V59eTdAkd96c+uEm6qYg+Y= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727360AbgIUOAF (ORCPT ); Mon, 21 Sep 2020 10:00:05 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:41462 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726496AbgIUOAE (ORCPT ); Mon, 21 Sep 2020 10:00:04 -0400 Received: by mail-lf1-f65.google.com with SMTP id y17so14130991lfa.8 for ; Mon, 21 Sep 2020 07:00:03 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=4/FdGn9Ta2As0651L0QV5CW8c4e0Ma+q3GzcN2EtOes=; b=iA2LLwWOndAMnyXD07XLwyHBno8/jY55uVdgZf4Hrm7PN7kkTkJn9vEj7xTpeAWC/Q bXgN8vf6dnmYHj+yjnRZ6MQRUK672W4bSR+yGs/+jC30gt0hgRMnW2+5JB97F90AnCMo etSFogQm2d8rrz55sV66UUUu207w6LCO642dlTC6MxBHV8vwQUiw6qkmz/DNwh/rISU5 mkfkspxZxaSPKyYtrJwKZksDx24FM/x1uwORaKb0NkPvEwHPfVUtOEyiRCCBiUqU8LCD rGsEB3N52uPb6QTCXZrfRdU79CLQDmKFc8NmM38g+Z4zO3tlKptRQiWskhTv3ImxGw9F d0EQ== X-Gm-Message-State: AOAM531kTuhb9aBZL4T4QcTDGxKfcm+VEUGZ1I95/u2pS7feBEmnC/5S osu+pvOvBNwuvjTD1y5OwA4= X-Google-Smtp-Source: ABdhPJywIhpbNWNU5CTb6hMjLaCsc2jG87gIS6zZ1reYA9Rb73VL4oVXy8Rbwm1NBQgyXYam34o/fA== X-Received: by 2002:a19:8089:: with SMTP id b131mr38374lfd.390.1600696802344; Mon, 21 Sep 2020 07:00:02 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id w9sm2612350lfn.224.2020.09.21.07.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 07:00:01 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kKMMF-0006Gy-4t; Mon, 21 Sep 2020 15:59:55 +0200 From: Johan Hovold To: Oliver Neukum Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, Daniel Caujolle-Bert , Johan Hovold Subject: [PATCH v2 3/4] USB: cdc-acm: use common data-class define Date: Mon, 21 Sep 2020 15:59:50 +0200 Message-Id: <20200921135951.24045-4-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200921135951.24045-1-johan@kernel.org> References: <20200921135951.24045-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use the data-class define provided by USB core and drop the driver-specific one. Signed-off-by: Johan Hovold --- drivers/usb/class/cdc-acm.c | 6 ++---- drivers/usb/class/cdc-acm.h | 2 -- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index f42ade505569..a361b937684a 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -1287,10 +1287,8 @@ static int acm_probe(struct usb_interface *intf, skip_normal_probe: /*workaround for switched interfaces */ - if (data_interface->cur_altsetting->desc.bInterfaceClass - != CDC_DATA_INTERFACE_TYPE) { - if (control_interface->cur_altsetting->desc.bInterfaceClass - == CDC_DATA_INTERFACE_TYPE) { + if (data_interface->cur_altsetting->desc.bInterfaceClass != USB_CLASS_CDC_DATA) { + if (control_interface->cur_altsetting->desc.bInterfaceClass == USB_CLASS_CDC_DATA) { dev_dbg(&intf->dev, "Your device has switched interfaces.\n"); swap(control_interface, data_interface); diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h index cd5e9d8ab237..b7174a0098a5 100644 --- a/drivers/usb/class/cdc-acm.h +++ b/drivers/usb/class/cdc-acm.h @@ -131,8 +131,6 @@ struct acm { unsigned long quirks; }; -#define CDC_DATA_INTERFACE_TYPE 0x0a - /* constants describing various quirks and errors */ #define NO_UNION_NORMAL BIT(0) #define SINGLE_RX_URB BIT(1) From patchwork Mon Sep 21 13:59:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11789915 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B68AE6CA for ; Mon, 21 Sep 2020 14:00:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F29420B1F for ; Mon, 21 Sep 2020 14:00:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600696807; bh=XaGvPDobjPLnZV1wSfgqDV//Dl3wwxhQh33+hdlHjP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=U5XFNCq452H9tvPUbhgeoaFq6bsRdxtEMDV9eGCDMNdDfjnZWW3vaLrd3xyE8oyAM TZAFV/D9yHff6jmUGo0SADqSgUN2gmhufG6idtzAPGw1FBjLbYsoTsiDeXwMGtYNrt KUjPvbfOVAT3PFMaZsbk3dVMpzg7LtRKUZNv1vcw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727371AbgIUOAG (ORCPT ); Mon, 21 Sep 2020 10:00:06 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:34166 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727356AbgIUOAG (ORCPT ); Mon, 21 Sep 2020 10:00:06 -0400 Received: by mail-lj1-f195.google.com with SMTP id v23so11218328ljd.1 for ; Mon, 21 Sep 2020 07:00:04 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=2pgMmvVc6BBJkuon8x/rXqtpns3TbySrtqQAZSWvaOE=; b=iwFMfk3bPMNP0TlvJuaWhQLDV591ZphhnvdvToAXqfNq+lH+s+6cxA/DOxmXN1P4Kq s1trMTOY0Fmnb6qrcGYFk3SBwlowKKWZIpbgoOhDi424ZG0N1PMNRn87rVupRon/c+/V MfLK088nOMEM2a6TBtgdijb6AmPS0Ar5dGaenHn54SGGsbzKKB5bF7hapiEYmnGwJAx4 68blnuosMxmd0HiUBHbMrITcDKRVcRIyqhgMPk/AiYJE1xfsrNDWMOtLETR77Zzt8iPj 891Lc/ZRiNRg1Wdjw7Ig7UOBwfhmP+eAz3af32lCbmMrcgfB9NZ/Jp/V5ENV2rr/qbVb shAg== X-Gm-Message-State: AOAM532QgVm9pt531M0JHkTqgTmOfAzfa2mnq/j54+yP9D7JXLqJqVhY B8iYExROCE8ed/rJuOmtRus= X-Google-Smtp-Source: ABdhPJxt8Kw0D8C7U/bO9Mdxdzf3tferk6c7J5YWwY1Mneldo05FdeSJ2MKu3okgUlVsupmMaHqqnQ== X-Received: by 2002:a2e:964a:: with SMTP id z10mr15589284ljh.463.1600696803928; Mon, 21 Sep 2020 07:00:03 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id i63sm2751718lji.66.2020.09.21.07.00.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 07:00:01 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kKMMF-0006H4-7V; Mon, 21 Sep 2020 15:59:55 +0200 From: Johan Hovold To: Oliver Neukum Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, Daniel Caujolle-Bert , Johan Hovold Subject: [PATCH v2 4/4] USB: cdc-acm: clean up no-union-descriptor handling Date: Mon, 21 Sep 2020 15:59:51 +0200 Message-Id: <20200921135951.24045-5-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200921135951.24045-1-johan@kernel.org> References: <20200921135951.24045-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org For interfaces that lack a union descriptor, probe for a "combined-interface" before falling back to the call-management descriptor instead of the other way round. This allows for the removal of the NO_DATA_INTERFACE quirk and makes the probe algorithm somewhat easier to follow. Signed-off-by: Johan Hovold --- drivers/usb/class/cdc-acm.c | 32 ++++++++++---------------------- drivers/usb/class/cdc-acm.h | 11 +++++------ 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index a361b937684a..357e896a4fc0 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -1218,26 +1218,19 @@ static int acm_probe(struct usb_interface *intf, call_intf_num = cmgmd->bDataInterface; if (!union_header) { - if (call_intf_num > 0) { + if (intf->cur_altsetting->desc.bNumEndpoints == 3) { + dev_dbg(&intf->dev, "No union descriptor, assuming single interface\n"); + combined_interfaces = 1; + control_interface = data_interface = intf; + goto look_for_collapsed_interface; + } else if (call_intf_num > 0) { dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n"); - /* quirks for Droids MuIn LCD */ - if (quirks & NO_DATA_INTERFACE) { - data_interface = usb_ifnum_to_if(usb_dev, 0); - } else { - data_intf_num = call_intf_num; - data_interface = usb_ifnum_to_if(usb_dev, data_intf_num); - } + data_intf_num = call_intf_num; + data_interface = usb_ifnum_to_if(usb_dev, data_intf_num); control_interface = intf; } else { - if (intf->cur_altsetting->desc.bNumEndpoints != 3) { - dev_dbg(&intf->dev,"No union descriptor, giving up\n"); - return -ENODEV; - } else { - dev_warn(&intf->dev,"No union descriptor, testing for castrated device\n"); - combined_interfaces = 1; - control_interface = data_interface = intf; - goto look_for_collapsed_interface; - } + dev_dbg(&intf->dev, "No union descriptor, giving up\n"); + return -ENODEV; } } else { int class = -1; @@ -1881,11 +1874,6 @@ static const struct usb_device_id acm_ids[] = { /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */ - /* Support for Droids MuIn LCD */ - { USB_DEVICE(0x04d8, 0x000b), - .driver_info = NO_DATA_INTERFACE, - }, - #if IS_ENABLED(CONFIG_INPUT_IMS_PCU) { USB_DEVICE(0x04d8, 0x0082), /* Application mode */ .driver_info = IGNORE_DEVICE, diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h index b7174a0098a5..b2135095898f 100644 --- a/drivers/usb/class/cdc-acm.h +++ b/drivers/usb/class/cdc-acm.h @@ -135,9 +135,8 @@ struct acm { #define NO_UNION_NORMAL BIT(0) #define SINGLE_RX_URB BIT(1) #define NO_CAP_LINE BIT(2) -#define NO_DATA_INTERFACE BIT(4) -#define IGNORE_DEVICE BIT(5) -#define QUIRK_CONTROL_LINE_STATE BIT(6) -#define CLEAR_HALT_CONDITIONS BIT(7) -#define SEND_ZERO_PACKET BIT(8) -#define DISABLE_ECHO BIT(9) +#define IGNORE_DEVICE BIT(3) +#define QUIRK_CONTROL_LINE_STATE BIT(4) +#define CLEAR_HALT_CONDITIONS BIT(5) +#define SEND_ZERO_PACKET BIT(6) +#define DISABLE_ECHO BIT(7)