From patchwork Thu Jan 21 10:29:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12035509 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFEF2C433E0 for ; Thu, 21 Jan 2021 10:32:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 994D823433 for ; Thu, 21 Jan 2021 10:32:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729315AbhAUKbn (ORCPT ); Thu, 21 Jan 2021 05:31:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:60232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729292AbhAUKbU (ORCPT ); Thu, 21 Jan 2021 05:31:20 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2389C23444; Thu, 21 Jan 2021 10:29:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611224971; bh=2a6eKV6ka6kZEf6Ox3YKBGQDv8NFUC/2/V+O9Rj3yJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=buEQiFy0gZ+L5hd7cfuwohcx24LtrMGVQQfepETEvvJlcepVS7a/MfkMWGWMJ+rkV GmS0q4GQzqyO9zeevbshnQ1sN2LUvER/3FvaSOmBSH3+lqe7LmcZ5zFlUPGRQe1KZ7 K5zLdFHjfD8N8NaWH9gwnd3e95O53MLEGuFMdnbVsatOGNJgV5kjvK8vlC6UAx0nyT V3OdmY9NF7g8yy05VrJrIg1V4QQm9+VZZ0YP0KyB0neSOWpt2dDah8qFpcHadAQcsX +IpAI7ezdqY29SfL8MDZtHXThPNaOkbKUqpWmMJp/MXvNB81r++rcDo0K9gZ3kHmV9 Z1aFj5o+NAoaw== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l2XDc-0004YH-I2; Thu, 21 Jan 2021 11:29:36 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Manivannan Sadhasivam , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 01/10] USB: serial: xr: fix NULL-deref at probe Date: Thu, 21 Jan 2021 11:29:13 +0100 Message-Id: <20210121102922.17439-3-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210121102922.17439-1-johan@kernel.org> References: <20210121102922.17439-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Make sure that the probed device has an interface 0 to avoid dereferencing a NULL pointer in case of a malicious device or during USB-descriptor fuzzing. Fixes: a8f54b7bd132 ("USB: serial: add MaxLinear/Exar USB to Serial driver") Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index bdb2df27b50b..7be6da6a5cf3 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -552,6 +552,9 @@ static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) /* But claim the control interface during data interface probe */ control_interface = usb_ifnum_to_if(usb_dev, 0); + if (!control_interface) + return -ENODEV; + ret = usb_driver_claim_interface(driver, control_interface, NULL); if (ret) { dev_err(&serial->interface->dev, "Failed to claim control interface\n"); From patchwork Thu Jan 21 10:29:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12036129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D48F2C433DB for ; Thu, 21 Jan 2021 13:17:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98DA3239FD for ; Thu, 21 Jan 2021 13:17:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729527AbhAUNDX (ORCPT ); Thu, 21 Jan 2021 08:03:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:59686 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729447AbhAUKaK (ORCPT ); Thu, 21 Jan 2021 05:30:10 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7F15A23899; Thu, 21 Jan 2021 10:29:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611224969; bh=l37/E/vH4XbFHwCeL/usOurAN4NyJR1QzSmrjcbEVUE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IeCt3T7xJntsvWfSdnZj23s60eW/tzIClgPhPw4LPMSdGpbnCgPDVjjnwbKWgVhLP SQlMROeEU6Yv/cxQ8XMt+xB25mP/FrJsRhqEXjXXM4JJZJl97smwrCf7F58z51BfSZ YOtwRKG8YBW69YzYo9EwphVdDyGNO6bZPAqNnHg3h8SehCRR++KvBinqCpVHf3dz9Q VRlix76zis9/0rVn9wy/laoDBeZwlmhvZkhCy8U5Z7rKe9gDmFh+4t58BR4kmvEf9I UmZTwcsupU5n4ShABu0eKhqAt12aR94azlCU1NKJssbq0Ftu4G4CUpkEqQlUzmcKhD CxNUlwpkrDJWg== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l2XDc-0004YK-Ks; Thu, 21 Jan 2021 11:29:36 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Manivannan Sadhasivam , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 02/10] USB: serial: xr: fix interface leak at disconnect Date: Thu, 21 Jan 2021 11:29:14 +0100 Message-Id: <20210121102922.17439-4-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210121102922.17439-1-johan@kernel.org> References: <20210121102922.17439-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Make sure to release the control interface at disconnect so that the driver can be unbound without leaking resources (and later rebound). Fixes: a8f54b7bd132 ("USB: serial: add MaxLinear/Exar USB to Serial driver") Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 7be6da6a5cf3..5e110b0c8e71 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -564,6 +564,15 @@ static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) return 0; } +static void xr_disconnect(struct usb_serial *serial) +{ + struct usb_driver *driver = serial->type->usb_driver; + struct usb_interface *control_interface; + + control_interface = usb_ifnum_to_if(serial->dev, 0); + usb_driver_release_interface(driver, control_interface); +} + static const struct usb_device_id id_table[] = { { USB_DEVICE(0x04e2, 0x1410) }, /* XR21V141X */ { } @@ -578,6 +587,7 @@ static struct usb_serial_driver xr_device = { .id_table = id_table, .num_ports = 1, .probe = xr_probe, + .disconnect = xr_disconnect, .open = xr_open, .close = xr_close, .break_ctl = xr_break_ctl, From patchwork Thu Jan 21 10:29:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12035501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF930C433E0 for ; Thu, 21 Jan 2021 10:31:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65BA6204EF for ; Thu, 21 Jan 2021 10:31:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729199AbhAUKau (ORCPT ); Thu, 21 Jan 2021 05:30:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:59704 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729449AbhAUKaK (ORCPT ); Thu, 21 Jan 2021 05:30:10 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9692F238E1; Thu, 21 Jan 2021 10:29:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611224969; bh=muBD3IQ1TCM0qBQYVRvhSbDGJU6BeU5w0afjk7NjGbs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r6ZIJg+uHqEEvjh9KRazuGtO3ToQJ09p5V6IUKO1F8IZowohPY+aI4TSaf+ARseJK MUk/ih3UCWa2KhANYsQIBGq0IXpW2xwpAJjdwCII7xRgaqXKjijkwwzwNtzewgCxlv cC6wD0tHv16UUGsw9XcbGvKd5aH/X33ID60BZaBVCaNHtYC6I8MThC7mE9ElRVqZGV FWmvImwZNvOxBGTwP25ZvwRp3Y5aHO61oAKYZTQr8xMmBGmnxtQCTFdrxTNI/+J8zO aG+1ctAW5bEJqEhzFYMnBpEUbrFY4zbMzQUkDPHL6XHQoBvEEft2QqLeMs39b9oXww /LmOtr9uBER0w== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l2XDc-0004YN-Np; Thu, 21 Jan 2021 11:29:36 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Manivannan Sadhasivam , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 03/10] USB: serial: xr: use subsystem usb_device at probe Date: Thu, 21 Jan 2021 11:29:15 +0100 Message-Id: <20210121102922.17439-5-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210121102922.17439-1-johan@kernel.org> References: <20210121102922.17439-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use the subsystem struct usb_device pointer at probe instead of deriving it from the interface pointer. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 5e110b0c8e71..8f81f866d681 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -541,7 +541,6 @@ static void xr_close(struct usb_serial_port *port) static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) { - struct usb_device *usb_dev = interface_to_usbdev(serial->interface); struct usb_driver *driver = serial->type->usb_driver; struct usb_interface *control_interface; int ret; @@ -551,7 +550,7 @@ static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) return -ENODEV; /* But claim the control interface during data interface probe */ - control_interface = usb_ifnum_to_if(usb_dev, 0); + control_interface = usb_ifnum_to_if(serial->dev, 0); if (!control_interface) return -ENODEV; From patchwork Thu Jan 21 10:29:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12036089 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0127C433DB for ; Thu, 21 Jan 2021 13:03:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5593D239FD for ; Thu, 21 Jan 2021 13:03:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731598AbhAUNDd (ORCPT ); Thu, 21 Jan 2021 08:03:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:60218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729287AbhAUKbU (ORCPT ); Thu, 21 Jan 2021 05:31:20 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 951CD238D7; Thu, 21 Jan 2021 10:29:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611224969; bh=cAZ+bdotNq2+OepIgVZlBcVcWLCXIE8JG8JDOtK1y0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aNu4QWe29ncRnTTRRqNLAhTO3N5Pxq22g4ct+MhNDnCmZL0JMowzE1UQcYcThdyie GZBlcZY1XFDsUd5YDCDtmFM3eaH/grtyX/yRfa3F8x6WMwxJ5b4TG8NV0Zi3ydqIve HjnLi4Tc9yxwa7adRgPq9/CyJ0rhLGI99X8Baj8LdX7LsIaRW3g7Lpl3XcjCrLxLcx D8LupIjWZqqfTgCYCiYh4NQX12fchVCFyJg9lCyomjUA9lnJZ+WDs1sNpDDhyIERSZ cHM64ncsUdOcnNhjW+mzqLwOzVqI3SqadhcixmtGgDxcTnMh21HzV/s6uxxEF1Rl1r NT92oIqElj2QA== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l2XDc-0004YR-R0; Thu, 21 Jan 2021 11:29:36 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Manivannan Sadhasivam , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 04/10] USB: serial: xr: use termios flag helpers Date: Thu, 21 Jan 2021 11:29:16 +0100 Message-Id: <20210121102922.17439-6-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210121102922.17439-1-johan@kernel.org> References: <20210121102922.17439-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use the termios flag helpers consistently, including for CRTSCTS. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 8f81f866d681..52909dccb4dc 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -401,7 +401,6 @@ static int xr_set_baudrate(struct tty_struct *tty, static void xr_set_flow_mode(struct tty_struct *tty, struct usb_serial_port *port) { - unsigned int cflag = tty->termios.c_cflag; u8 flow, gpio_mode; int ret; @@ -409,7 +408,7 @@ static void xr_set_flow_mode(struct tty_struct *tty, if (ret) return; - if (cflag & CRTSCTS) { + if (C_CRTSCTS(tty)) { dev_dbg(&port->dev, "Enabling hardware flow ctrl\n"); /* From patchwork Thu Jan 21 10:29:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12036097 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47E79C433DB for ; Thu, 21 Jan 2021 13:04:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D737123A00 for ; Thu, 21 Jan 2021 13:04:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730954AbhAUND7 (ORCPT ); Thu, 21 Jan 2021 08:03:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:59658 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729441AbhAUKaK (ORCPT ); Thu, 21 Jan 2021 05:30:10 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5B4E62343E; Thu, 21 Jan 2021 10:29:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611224969; bh=yZsEYFxHhExQyS17apsnmD2VNyi2e+mhEdvR9PE0M50=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PEKOd7okSE0hOqSVsTuk9LeSDjr7FBeAV5S+INLLYQ7R8bdpwPuUhUyGjSou9t12X Crr4MGyXGaq7AMx9fg/v0PuKmdsQEAXAvB34jucYb5iYu/hSKSyZ24L2bd8XDpccEr B4GtBq5lxRvAIkl4/Nx3gDQRD5aID930mP7BVzk/1CoIDWMHTH3F5ZeZ5ncYfTxi7H tHyomuaTXzrg77aJAgEVgYlbbO3DZs68QaNfs8Hu7jbHDoMYu/jWJHAOjAwk44mwMY /vZOLyIcaE3UKyswCUXifiayurVjO7kLb6ibpfR53ehQwRFrelSNDGZWOxDSZjf5p4 JJxltK3lmV9tw== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l2XDc-0004YU-UL; Thu, 21 Jan 2021 11:29:36 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Manivannan Sadhasivam , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 05/10] USB: serial: xr: document vendor-request recipient Date: Thu, 21 Jan 2021 11:29:17 +0100 Message-Id: <20210121102922.17439-7-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210121102922.17439-1-johan@kernel.org> References: <20210121102922.17439-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add the missing device-recipient define to the vendor control requests for completeness. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 52909dccb4dc..202263211ba9 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -116,8 +116,8 @@ static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) ret = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), XR21V141X_SET_REQ, - USB_DIR_OUT | USB_TYPE_VENDOR, val, - reg | (block << 8), NULL, 0, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + val, reg | (block << 8), NULL, 0, USB_CTRL_SET_TIMEOUT); if (ret < 0) { dev_err(&port->dev, "Failed to set reg 0x%02x: %d\n", reg, ret); @@ -140,8 +140,8 @@ static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), XR21V141X_GET_REQ, - USB_DIR_IN | USB_TYPE_VENDOR, 0, - reg | (block << 8), dmabuf, 1, + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + 0, reg | (block << 8), dmabuf, 1, USB_CTRL_GET_TIMEOUT); if (ret == 1) { *val = *dmabuf; From patchwork Thu Jan 21 10:29:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12036091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95E61C433E0 for ; Thu, 21 Jan 2021 13:03:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D2C5239FF for ; Thu, 21 Jan 2021 13:03:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731609AbhAUNDg (ORCPT ); Thu, 21 Jan 2021 08:03:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:60220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729272AbhAUKbU (ORCPT ); Thu, 21 Jan 2021 05:31:20 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9AA94238E2; Thu, 21 Jan 2021 10:29:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611224969; bh=xjg4bJ/WJ7UGY2kaqmpOdGZkHckPyPqK/EUxrrD9Eu0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ATQ1FSqCg5HJuJsGlh9XsipX3j0BDNJ6MttLxQdqPRBx3D1M3V1sdVbfebK7fqtyh QjP0uYeW6zZfDjW14utme2iJNcumkwMsI2faC51MTwC1UP/3sJPOe0ptGidoK1YCFW z7n5qGgRcSHMiNUSnv5qx30JlZ1tXaTkU/U2q7XFq9q6nCTbuzDNK/JIDx+5RmQcYb 9P8NcrpbPxx8g3oYQ/LN0DsYldmhrkmNMXBnXE6GMRFjTlZOunb6qsOtzfWGb708EK RTL0Xtbl/Yup6MLKRR9kyogjrmGxSal/8xJFRDXyzUFRD7n1jW33f/zNirX+lu0sFs gG9viQqb8RvNA== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l2XDd-0004YW-1c; Thu, 21 Jan 2021 11:29:37 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Manivannan Sadhasivam , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 06/10] USB: serial: xr: clean up line-settings handling Date: Thu, 21 Jan 2021 11:29:18 +0100 Message-Id: <20210121102922.17439-8-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210121102922.17439-1-johan@kernel.org> References: <20210121102922.17439-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Shift the line-setting values when defining them rather than in set_termios() for consistency and improved readability. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 202263211ba9..2000277bacc1 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -71,17 +71,17 @@ struct xr_txrx_clk_mask { #define XR21V141X_UART_DATA_8 0x8 #define XR21V141X_UART_PARITY_MASK GENMASK(6, 4) -#define XR21V141X_UART_PARITY_SHIFT 0x4 -#define XR21V141X_UART_PARITY_NONE 0x0 -#define XR21V141X_UART_PARITY_ODD 0x1 -#define XR21V141X_UART_PARITY_EVEN 0x2 -#define XR21V141X_UART_PARITY_MARK 0x3 -#define XR21V141X_UART_PARITY_SPACE 0x4 +#define XR21V141X_UART_PARITY_SHIFT 4 +#define XR21V141X_UART_PARITY_NONE (0x0 << XR21V141X_UART_PARITY_SHIFT) +#define XR21V141X_UART_PARITY_ODD (0x1 << XR21V141X_UART_PARITY_SHIFT) +#define XR21V141X_UART_PARITY_EVEN (0x2 << XR21V141X_UART_PARITY_SHIFT) +#define XR21V141X_UART_PARITY_MARK (0x3 << XR21V141X_UART_PARITY_SHIFT) +#define XR21V141X_UART_PARITY_SPACE (0x4 << XR21V141X_UART_PARITY_SHIFT) #define XR21V141X_UART_STOP_MASK BIT(7) -#define XR21V141X_UART_STOP_SHIFT 0x7 -#define XR21V141X_UART_STOP_1 0x0 -#define XR21V141X_UART_STOP_2 0x1 +#define XR21V141X_UART_STOP_SHIFT 7 +#define XR21V141X_UART_STOP_1 (0x0 << XR21V141X_UART_STOP_SHIFT) +#define XR21V141X_UART_STOP_2 (0x1 << XR21V141X_UART_STOP_SHIFT) #define XR21V141X_UART_FLOW_MODE_NONE 0x0 #define XR21V141X_UART_FLOW_MODE_HW 0x1 @@ -477,25 +477,21 @@ static void xr_set_termios(struct tty_struct *tty, if (C_PARENB(tty)) { if (C_CMSPAR(tty)) { if (C_PARODD(tty)) - bits |= XR21V141X_UART_PARITY_MARK << - XR21V141X_UART_PARITY_SHIFT; + bits |= XR21V141X_UART_PARITY_MARK; else - bits |= XR21V141X_UART_PARITY_SPACE << - XR21V141X_UART_PARITY_SHIFT; + bits |= XR21V141X_UART_PARITY_SPACE; } else { if (C_PARODD(tty)) - bits |= XR21V141X_UART_PARITY_ODD << - XR21V141X_UART_PARITY_SHIFT; + bits |= XR21V141X_UART_PARITY_ODD; else - bits |= XR21V141X_UART_PARITY_EVEN << - XR21V141X_UART_PARITY_SHIFT; + bits |= XR21V141X_UART_PARITY_EVEN; } } if (C_CSTOPB(tty)) - bits |= XR21V141X_UART_STOP_2 << XR21V141X_UART_STOP_SHIFT; + bits |= XR21V141X_UART_STOP_2; else - bits |= XR21V141X_UART_STOP_1 << XR21V141X_UART_STOP_SHIFT; + bits |= XR21V141X_UART_STOP_1; ret = xr_set_reg_uart(port, XR21V141X_REG_FORMAT, bits); if (ret) From patchwork Thu Jan 21 10:29:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12036063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33416C433DB for ; Thu, 21 Jan 2021 12:58:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9444B239FD for ; Thu, 21 Jan 2021 12:58:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729266AbhAUKbb (ORCPT ); Thu, 21 Jan 2021 05:31:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:60222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729273AbhAUKbU (ORCPT ); Thu, 21 Jan 2021 05:31:20 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B89ED238EE; Thu, 21 Jan 2021 10:29:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611224969; bh=E3rqOhlNjsoj1qD6go+1xdGHgfZsx2+E9ZgBMrIJGPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rCHPjIgRidSetEiDc/rT5Ghl1rwpxwhraSA2gf7FL8ZILU3DCyF+dffdL10fZg+Lj n1AV7tutGE05vSTha7KYM3Nivlu/ZC/3oWAl3IhcSrRiDssMlnBtPTXXhbGH/95KL0 Wu2Brx46b3KGRom5yCT7zhEZ9SAiYiNpN75qfMKPmy+A/eq12BPrkbvhd1Hdi+9hkV CzqSnkYeL7N5849hKFLbNzU2CVV78CiDnN9+mqkQRKB3lRWSlKGH5JblMYSZdM+mlJ u+qCtJqxHlz3YWwm4dehjrDmOVZB6xrwv3ipl+F/oPFDrDZMP0D9Uxg87C/YA9k2KB nz2zD5fiwkkoQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l2XDd-0004Ya-5B; Thu, 21 Jan 2021 11:29:37 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Manivannan Sadhasivam , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 07/10] USB: serial: xr: simplify line-speed logic Date: Thu, 21 Jan 2021 11:29:19 +0100 Message-Id: <20210121102922.17439-9-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210121102922.17439-1-johan@kernel.org> References: <20210121102922.17439-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Simplify the changed-line-speed conditional expression. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 2000277bacc1..fc727f4283f2 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -451,8 +451,7 @@ static void xr_set_termios(struct tty_struct *tty, u8 bits = 0; int ret; - if ((old_termios && tty->termios.c_ospeed != old_termios->c_ospeed) || - !old_termios) + if (!old_termios || (tty->termios.c_ospeed != old_termios->c_ospeed)) xr_set_baudrate(tty, port); switch (C_CSIZE(tty)) { From patchwork Thu Jan 21 10:29:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12036093 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2C57C433DB for ; Thu, 21 Jan 2021 13:03:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6EA1E239FD for ; Thu, 21 Jan 2021 13:03:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731614AbhAUNDj (ORCPT ); Thu, 21 Jan 2021 08:03:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:60230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729297AbhAUKbU (ORCPT ); Thu, 21 Jan 2021 05:31:20 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D6B7C239E7; Thu, 21 Jan 2021 10:29:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611224970; bh=LB7JmBqWiGACFdERW0/yScBVALQ/zUAt6uErRz6Q0Pc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QbvEIKNKDcVf2nhJ8r5xynsebn/9kNQ84p1/eJlBNBd5yZCJzqHAlYFD9U6BMQ122 EWyQx/nb1IxRdaGrOdEHJ9OK7zBpVNO1aua/YsaD8pfNs00qEv3tyU2oa3NXnaF0n3 To9n6l6JKHAP1REIMo0mZ+/ALfDX0MciawSfbQaPjzhhh/VOMtXrWItU0jr9TXFWrJ MzqhTQP/fbHrRmd/bKG8+3+M9LcY/6nUE4NzeQ73QeQ2xe9yJW08BZ6DZJG/A+lDe4 QU2csgJJEqGYO8jls2EEvQTWYvHAqJkb1m8UAlgcDtqH1NjvhFmt4+BORtrZ+r621D pBR051hjMS98Q== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l2XDd-0004Yd-8U; Thu, 21 Jan 2021 11:29:37 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Manivannan Sadhasivam , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 08/10] USB: serial: xr: fix gpio-mode handling Date: Thu, 21 Jan 2021 11:29:20 +0100 Message-Id: <20210121102922.17439-10-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210121102922.17439-1-johan@kernel.org> References: <20210121102922.17439-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Fix the gpio-mode handling so that all the pins are under driver control (i.e. in gpio mode) when hardware flow control is disabled. This is specifically needed to be able to control RTS. Fixes: a8f54b7bd132 ("USB: serial: add MaxLinear/Exar USB to Serial driver") Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index fc727f4283f2..183731cd2ef7 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -408,14 +408,11 @@ static void xr_set_flow_mode(struct tty_struct *tty, if (ret) return; + /* Set GPIO mode for controlling the pins manually by default. */ + gpio_mode &= ~XR21V141X_UART_MODE_GPIO_MASK; + if (C_CRTSCTS(tty)) { dev_dbg(&port->dev, "Enabling hardware flow ctrl\n"); - - /* - * RTS/CTS is the default flow control mode, so set GPIO mode - * for controlling the pins manually by default. - */ - gpio_mode &= ~XR21V141X_UART_MODE_GPIO_MASK; gpio_mode |= XR21V141X_UART_MODE_RTS_CTS; flow = XR21V141X_UART_FLOW_MODE_HW; } else if (I_IXON(tty)) { From patchwork Thu Jan 21 10:29:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12036087 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 600B8C433E0 for ; Thu, 21 Jan 2021 13:03:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1BE6E239FD for ; Thu, 21 Jan 2021 13:03:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731590AbhAUND3 (ORCPT ); Thu, 21 Jan 2021 08:03:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:60224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729276AbhAUKbU (ORCPT ); Thu, 21 Jan 2021 05:31:20 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C80CA2399A; Thu, 21 Jan 2021 10:29:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611224969; bh=DEeqkkmfzEshOH9YcHBTh0nZBMY1kefvozqEmVaGwrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HoZVQnIfaIcftewG35mfdBs0Y22w215QvhpVz0YmxMvmWz7iSdBHXcsWmdvDvmygT E02t+4D74xIYR8BAMctLk1QRdYnS85gkaD6dpYcVlm6pdu9aCj3KU58Go9tOBw7jVs jJahfNOiZ7/+xahSl8lvGI27B71E5UEe9WAg7wWPFHhwi9jIq/b3qYdO8tEUr2nwAv vBhMjZtsbma0Y3zTv/I8fjId3oyF5PwE+2xWsq8IU35cjzdDHAmBesu8I6ruaB62B0 taFq1SNw3dcWLPzXhU2NqLAKK3zD+RlnRJJF1gDlGov0/F498uwZGbd4qSK666an7v xzS0NTBcKNbnw== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l2XDd-0004Yg-C6; Thu, 21 Jan 2021 11:29:37 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Manivannan Sadhasivam , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 09/10] USB: serial: xr: fix pin configuration Date: Thu, 21 Jan 2021 11:29:21 +0100 Message-Id: <20210121102922.17439-11-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210121102922.17439-1-johan@kernel.org> References: <20210121102922.17439-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Make sure that the modem pins are set up correctly when opening the port to avoid leaving, for example, DTR and RTS configured as inputs, which is the device default. This is specifically needed to be able to control DTR and RTS when hardware flow control is disabled. Fixes: a8f54b7bd132 ("USB: serial: add MaxLinear/Exar USB to Serial driver") Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 183731cd2ef7..f67e7dba9509 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -502,6 +502,7 @@ static void xr_set_termios(struct tty_struct *tty, static int xr_open(struct tty_struct *tty, struct usb_serial_port *port) { + u8 gpio_dir; int ret; ret = xr_uart_enable(port); @@ -510,6 +511,13 @@ static int xr_open(struct tty_struct *tty, struct usb_serial_port *port) return ret; } + /* + * Configure DTR and RTS as outputs and RI, CD, DSR and CTS as + * inputs. + */ + gpio_dir = XR21V141X_UART_MODE_DTR | XR21V141X_UART_MODE_RTS; + xr_set_reg_uart(port, XR21V141X_REG_GPIO_DIR, gpio_dir); + /* Setup termios */ if (tty) xr_set_termios(tty, port, NULL); From patchwork Thu Jan 21 10:29:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12036131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 899BEC433E0 for ; Thu, 21 Jan 2021 13:17:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A2E023A01 for ; Thu, 21 Jan 2021 13:17:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731491AbhAUND0 (ORCPT ); Thu, 21 Jan 2021 08:03:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:60228 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729294AbhAUKbU (ORCPT ); Thu, 21 Jan 2021 05:31:20 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E3562239EB; Thu, 21 Jan 2021 10:29:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611224970; bh=v5TgOwXWj0YY94HrnCt3iZPfS8p5FlPm3RviRv/L0ME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mKY1pyJ5iW32eEeBPWbGWV4NQzWsqnbFjXsBeshkGsrUCN1s35y819qTxGvcME6H1 F20FMpcEU8JHAJjwQQXXrFj4HHLcDFTp40F+nr/aW6KNm8AhgESBChwxTKwlgtcnPx athTudEMfwVgz0ygLTzGDk5PDX0SvHjpmTiSSP9rTaHE6a+otvPpZRWWz3+QcV4Kfr frVdJD5r193stCExKb2PXyhSA5N6qwb7HtQdKmVoGUCIROHBxsBr2ARmeY2J46cGMl eUeeoO85RR2s8pPvQ3G22lXcMBRuozk+1mghQOybuSFMELPAzM01Uf7oT6MyFyUXUi AvGHeHZW6TAqw== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l2XDd-0004Yj-Fe; Thu, 21 Jan 2021 11:29:37 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Manivannan Sadhasivam , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 10/10] USB: serial: xr: fix B0 handling Date: Thu, 21 Jan 2021 11:29:22 +0100 Message-Id: <20210121102922.17439-12-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210121102922.17439-1-johan@kernel.org> References: <20210121102922.17439-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Fix up B0 handling which should leave the baud rate unchanged and specifically not report back a non-B0 rate when B0 is requested; must temporarily disable hardware flow control so that RTS can be deasserted; and should reassert DTR/RTS when moving from B0. Fixes: a8f54b7bd132 ("USB: serial: add MaxLinear/Exar USB to Serial driver") Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index f67e7dba9509..483d07dee19d 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -341,8 +341,11 @@ static int xr_set_baudrate(struct tty_struct *tty, u16 tx_mask, rx_mask; int ret; - baud = clamp(tty->termios.c_ospeed, XR21V141X_MIN_SPEED, - XR21V141X_MAX_SPEED); + baud = tty->termios.c_ospeed; + if (!baud) + return 0; + + baud = clamp(baud, XR21V141X_MIN_SPEED, XR21V141X_MAX_SPEED); divisor = XR_INT_OSC_HZ / baud; idx = ((32 * XR_INT_OSC_HZ) / baud) & 0x1f; tx_mask = xr21v141x_txrx_clk_masks[idx].tx; @@ -399,7 +402,8 @@ static int xr_set_baudrate(struct tty_struct *tty, } static void xr_set_flow_mode(struct tty_struct *tty, - struct usb_serial_port *port) + struct usb_serial_port *port, + struct ktermios *old_termios) { u8 flow, gpio_mode; int ret; @@ -411,7 +415,7 @@ static void xr_set_flow_mode(struct tty_struct *tty, /* Set GPIO mode for controlling the pins manually by default. */ gpio_mode &= ~XR21V141X_UART_MODE_GPIO_MASK; - if (C_CRTSCTS(tty)) { + if (C_CRTSCTS(tty) && C_BAUD(tty) != B0) { dev_dbg(&port->dev, "Enabling hardware flow ctrl\n"); gpio_mode |= XR21V141X_UART_MODE_RTS_CTS; flow = XR21V141X_UART_FLOW_MODE_HW; @@ -438,6 +442,11 @@ static void xr_set_flow_mode(struct tty_struct *tty, xr_uart_enable(port); xr_set_reg_uart(port, XR21V141X_REG_GPIO_MODE, gpio_mode); + + if (C_BAUD(tty) == B0) + xr_dtr_rts(port, 0); + else if (old_termios && (old_termios->c_cflag & CBAUD) == B0) + xr_dtr_rts(port, 1); } static void xr_set_termios(struct tty_struct *tty, @@ -493,11 +502,7 @@ static void xr_set_termios(struct tty_struct *tty, if (ret) return; - /* If baud rate is B0, clear DTR and RTS */ - if (C_BAUD(tty) == B0) - xr_dtr_rts(port, 0); - - xr_set_flow_mode(tty, port); + xr_set_flow_mode(tty, port, old_termios); } static int xr_open(struct tty_struct *tty, struct usb_serial_port *port)