Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1318012yba; Tue, 2 Apr 2019 06:47:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzof6butEM3DqKKIxr9RP1J0dDjZTNe8iPSzPM8o+mITA5GIs+Xm1J6CTLdHDVZBdkR9bt2 X-Received: by 2002:a63:36ce:: with SMTP id d197mr17556904pga.180.1554212820694; Tue, 02 Apr 2019 06:47:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554212820; cv=none; d=google.com; s=arc-20160816; b=YlDTKttD97gWAkXMAdhGYmiW4NlKunQjGPrq8J3CJRsF/m+FCjboQRVGCS0eQoDNVr Otcxv64mFK4muPF4Rny04QwK3qyhxmfRQqchGBg2jYLIzsWqpqiLRJ9qWVHTwoq9MhU/ ZaG1Ebd/EMeRaZEoUZDdpnXLbeZLon1gYJoWdomisBEKH0Q2YOMFWZTevEuRsjFw+q6M MRL2vIKeBtyjFUo+zcwn6sFx69G7MRzezrdO2lfROip1TXOoY1cqZjwUP1zruqvptxZH ju3l/XRPonOP/k2ZhqvhWnZFB+I38rgd4XXpxbPuYRxuJWz3pbjr48ifa73fCD30npUR eB0Q== 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; bh=QieQ/wc+k5gj9TSBm4gkbi+HgyED1XvVJxA6xotPxFs=; b=KS/zQKCbmx2Np8AGMhARSa085Q/JZxgJQhXblnUIiOuVjc5LBKKnHatfQCwvDm8hsx clsWJpzAmc4orxeuudhKPvuhYEZlLA4XDbFqPtz2NSnZmlJ2GJCgJihyUpzs9vsZVAf4 nxQ+TSqq94/7lpJ67A2bkVgBh9nLJO4z3jeqgwU9l6tJVwG18Evju1G8MZiXfKZ2H68u /rR4W6X+AuteXvdNG9NCc/Q1rlrpHIGFi69Jo3T2xzL9iLKQ90r54Uvk/bdodTVdma2R QnOpRklXSIQLK1VVZRECMUqKS4pxA8h+47IpGL434DP6IY15fei6g3CKaObbRDi/xKwT P/Hw== 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 71si5781565plc.97.2019.04.02.06.46.45; Tue, 02 Apr 2019 06:47:00 -0700 (PDT) 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 S1732009AbfDBNoY (ORCPT + 99 others); Tue, 2 Apr 2019 09:44:24 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:43454 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731477AbfDBNkI (ORCPT ); Tue, 2 Apr 2019 09:40:08 -0400 Received: from [167.98.27.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hBJe0-0002og-JA; Tue, 02 Apr 2019 14:40:04 +0100 Received: from ben by deadeye with local (Exim 4.92) (envelope-from ) id 1hBJdx-0004vv-82; Tue, 02 Apr 2019 14:40:01 +0100 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, Denis Kirjanov , "Oliver Neukum" , "Macpaul Lin" , "Greg Kroah-Hartman" , "Johan Hovold" Date: Tue, 02 Apr 2019 14:38:27 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 68/99] cdc-acm: fix abnormal DATA RX issue for Mediatek Preloader. In-Reply-To: X-SA-Exim-Connect-IP: 167.98.27.226 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.65-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Macpaul Lin commit eafb27fa5283599ce6c5492ea18cf636a28222bb upstream. Mediatek Preloader is a proprietary embedded boot loader for loading Little Kernel and Linux into device DRAM. This boot loader also handle firmware update. Mediatek Preloader will be enumerated as a virtual COM port when the device is connected to Windows or Linux OS via CDC-ACM class driver. When the USB enumeration has been done, Mediatek Preloader will send out handshake command "READY" to PC actively instead of waiting command from the download tool. Since Linux 4.12, the commit "tty: reset termios state on device registration" (93857edd9829e144acb6c7e72d593f6e01aead66) causes Mediatek Preloader receiving some abnoraml command like "READYXX" as it sent. This will be recognized as an incorrect response. The behavior change also causes the download handshake fail. This change only affects subsequent connects if the reconnected device happens to get the same minor number. By disabling the ECHO termios flag could avoid this problem. However, it cannot be done by user space configuration when download tool open /dev/ttyACM0. This is because the device running Mediatek Preloader will send handshake command "READY" immediately once the CDC-ACM driver is ready. This patch wants to fix above problem by introducing "DISABLE_ECHO" property in driver_info. When Mediatek Preloader is connected, the CDC-ACM driver could disable ECHO flag in termios to avoid the problem. Signed-off-by: Macpaul Lin Reviewed-by: Johan Hovold Acked-by: Oliver Neukum Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ben Hutchings --- drivers/usb/class/cdc-acm.c | 10 ++++++++++ drivers/usb/class/cdc-acm.h | 1 + 2 files changed, 11 insertions(+) --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -499,6 +499,13 @@ static int acm_tty_install(struct tty_dr if (retval) goto error_init_termios; + /* + * Suppress initial echoing for some devices which might send data + * immediately after acm driver has been installed. + */ + if (acm->quirks & DISABLE_ECHO) + tty->termios.c_lflag &= ~ECHO; + tty->driver_data = acm; return 0; @@ -1690,6 +1697,9 @@ static const struct usb_device_id acm_id { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */ .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ }, + { USB_DEVICE(0x0e8d, 0x2000), /* MediaTek Inc Preloader */ + .driver_info = DISABLE_ECHO, /* DISABLE ECHO in termios flag */ + }, { USB_DEVICE(0x0e8d, 0x3329), /* MediaTek Inc GPS */ .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ }, --- a/drivers/usb/class/cdc-acm.h +++ b/drivers/usb/class/cdc-acm.h @@ -135,3 +135,4 @@ struct acm { #define QUIRK_CONTROL_LINE_STATE BIT(6) #define CLEAR_HALT_CONDITIONS BIT(7) #define SEND_ZERO_PACKET BIT(8) +#define DISABLE_ECHO BIT(9)