From patchwork Tue May 17 11:07:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 12852294 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8CA54C433F5 for ; Tue, 17 May 2022 11:09:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sq2eiLuVCChXOcMV+jl6WNYbqMT2Q2o47YaeoL4ShZA=; b=cmmqXZ4Mga6wpE r4iXMviSIVb/iek5uWGoAgpXw7Qd0v4hCfRyUsDd6udAtltFNG7XeNbYdFUT5PD3EalAwRODODr6G TX44c5sC0ZYTyp/7gxJcurfpcKAx4EHlUTpaa4XOZnW303M3sTRad+wsswdxKvrdh2K2bpeRgRLyD mmKEVp/ci2gmEfjUsfBF93c0c590FZ7HIeVcqnUfEwBSVFTqP27s1qXQu0gBd1S+g95beprNlQQKG tyzv4Ghn5koddTl2AbUIF0qGES2VF1FfuiFdi32Ed6z8GDJAbssXQZaq3gGRjhLpYqPU1zYEPUmiu zHSq83/hG0shr7zryQJw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nqv3i-00DHPR-1M; Tue, 17 May 2022 11:08:10 +0000 Received: from mga04.intel.com ([192.55.52.120]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nqv3e-00DHMO-Fk for linux-arm-kernel@lists.infradead.org; Tue, 17 May 2022 11:08:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652785686; x=1684321686; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9slmVJB08S/xmRyUkvYJ6Tki39bkbQlupsPD2XkQ7Yw=; b=JPvRh9Nn/hCSlo/ERF7fbs3ZJf1cq/dd11bLSG8SuR8XvGvzwPtYd0t+ lFDEWzaYQIQZVKbgtT0WQE6b3GgAfBavaETbK0+UuSjdSbF3WtpKUmTqQ qMFyf5pMldY2TFWXNiYL9mNQw0bu62R28oq+abosNrI7pmNs/KGxoqWF+ bUwZqGzx54o5SpNkxoHobxFN89eCJnTvczwgbLd1mj688d1yesnWNoJSC 45F/zmqvu+sSJ3r87RmsLUXNubqOWATfu9y9rG/20fQW0xkOSrdbPYAPW NTtziz2M7MEVkA1RPFk9pSy0toLDTDQ7p5eqefj+/K7BMCVKdTY3vXCpS w==; X-IronPort-AV: E=McAfee;i="6400,9594,10349"; a="269969378" X-IronPort-AV: E=Sophos;i="5.91,232,1647327600"; d="scan'208";a="269969378" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2022 04:08:01 -0700 X-IronPort-AV: E=Sophos;i="5.91,232,1647327600"; d="scan'208";a="568830955" Received: from mtarral-mobl.ger.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.252.52.88]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2022 04:07:58 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-serial@vger.kernel.org, Greg KH , Jiri Slaby , Baruch Siach , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH 2/9] serial: digicolor-usart: Don't allow CS5-6 Date: Tue, 17 May 2022 14:07:30 +0300 Message-Id: <20220517110737.37148-3-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220517110737.37148-1-ilpo.jarvinen@linux.intel.com> References: <20220517110737.37148-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220517_040806_587442_9A3E52DE X-CRM114-Status: UNSURE ( 9.50 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Only CS7 and CS8 seem supported but CSIZE is not sanitized to CS8 in the default: block. Set CSIZE correctly so that userspace knows the effective value. Incorrect CSIZE also results in miscalculation of the frame bits in tty_get_char_size() or in its predecessor where the roughly the same code is directly within uart_update_timeout(). Cc: Baruch Siach Fixes: 5930cb3511df (serial: driver for Conexant Digicolor USART) Signed-off-by: Ilpo Järvinen Acked-by: Baruch Siach --- drivers/tty/serial/digicolor-usart.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/tty/serial/digicolor-usart.c b/drivers/tty/serial/digicolor-usart.c index 6d70fea76bb3..65e653eb5026 100644 --- a/drivers/tty/serial/digicolor-usart.c +++ b/drivers/tty/serial/digicolor-usart.c @@ -309,6 +309,8 @@ static void digicolor_uart_set_termios(struct uart_port *port, case CS8: default: config |= UA_CONFIG_CHAR_LEN; + termios->c_cflag &= ~CSIZE; + termios->c_cflag |= CS8; break; } From patchwork Tue May 17 11:07:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 12852293 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B510C433EF for ; Tue, 17 May 2022 11:09:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2Wdfs/Lohqvaqekf9FV1xUmAFBtFSATlf3l3O/Rv3dc=; b=SyfVXEuKFEgSOt 9RyEKj46c7LHnIjUYE8i+SD8nZRugdOOUvdjchz4FJCVPFKM4/LGw4ZyckGUlt9aQI6k9gOxvziRG tnPIOOqPZUAII+9t2NW0XRcyKrwUQctW1uN9MY5vicp040G5smZQnHmXn+42lkP1Lkb7y9kX5gk5X KG/vwzJNAd7dpb7GGsJBrMMSI/UgyiJvhIu6TZmf37cfsnoenmkzHX0oorXXEY+hYOgbeTF3mdBkW vbE0U16kvN6E3kNszV58DruxrbZNZqWPHKasIIeETlJOFyMx4V5JfG09WPd0Axh1+Twalv8xcu0Yv Xk8By5h4bBCpIim6LWFw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nqv3t-00DHWi-7S; Tue, 17 May 2022 11:08:21 +0000 Received: from mga04.intel.com ([192.55.52.120]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nqv3f-00DHOD-0D; Tue, 17 May 2022 11:08:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652785686; x=1684321686; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3rLSxMemifcCya5x4k0dLXnkqmQGBK5a9aBX6E+21uY=; b=OuA5k01erH6lb9n805GCn8wgOYj7ucLzfjwDCqokDNe41gj7f3CuxJzW zbKgCWhtHYAwllOMgrWl6Q+cGFMBGYjMLbZM1pbLzcepgbhelGr3VppFb 44EHs5p386xBVdKCbXglrtPX1XgS56Oyd5ZloQFi7ESUXJuj3zpPgjYCS ukFsAAbPsDOgkzGoTH2VhFUaxDJXeujZOSas6dCNnjVG1tipjuz7WodI5 bbURJvxqDU9tsRssZH+c4QK8kgfLdnuFQvkmePs5YwUpjkvDrWoao/C7w IlIT8+oEnmtLG6Wd0o+KkBB675Zf5NGibEUZy1TZPShOOC1TMgImizcFO A==; X-IronPort-AV: E=McAfee;i="6400,9594,10349"; a="269969393" X-IronPort-AV: E=Sophos;i="5.91,232,1647327600"; d="scan'208";a="269969393" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2022 04:08:05 -0700 X-IronPort-AV: E=Sophos;i="5.91,232,1647327600"; d="scan'208";a="568830979" Received: from mtarral-mobl.ger.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.252.52.88]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2022 04:08:01 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-serial@vger.kernel.org, Greg KH , Jiri Slaby , Manivannan Sadhasivam , Olof Johansson , =?utf-8?q?Andreas_F=C3=A4rber?= , Arnd Bergmann , linux-arm-kernel@lists.infradead.org, linux-unisoc@lists.infradead.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH 3/9] serial: rda-uart: Don't allow CS5-6 Date: Tue, 17 May 2022 14:07:31 +0300 Message-Id: <20220517110737.37148-4-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220517110737.37148-1-ilpo.jarvinen@linux.intel.com> References: <20220517110737.37148-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220517_040807_086965_93F8E987 X-CRM114-Status: UNSURE ( 8.64 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Only CS7 and CS8 are supported but CSIZE is not sanitized after fallthrough from CS5 or CS6 to CS7. Set CSIZE correctly so that userspace knows the effective value. Incorrect CSIZE also results in miscalculation of the frame bits in tty_get_char_size() or in its predecessor where the roughly the same code is directly within uart_update_timeout(). Cc: Manivannan Sadhasivam Fixes: c10b13325ced (tty: serial: Add RDA8810PL UART driver) Signed-off-by: Ilpo Järvinen --- drivers/tty/serial/rda-uart.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/tty/serial/rda-uart.c b/drivers/tty/serial/rda-uart.c index e5f1fded423a..f556b4955f59 100644 --- a/drivers/tty/serial/rda-uart.c +++ b/drivers/tty/serial/rda-uart.c @@ -262,6 +262,8 @@ static void rda_uart_set_termios(struct uart_port *port, fallthrough; case CS7: ctrl &= ~RDA_UART_DBITS_8; + termios->c_cflag &= ~CSIZE; + termios->c_cflag |= CS7; break; default: ctrl |= RDA_UART_DBITS_8; From patchwork Tue May 17 11:07:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 12852295 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A46DC433EF for ; Tue, 17 May 2022 11:09:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qtDFugGtGqHjYIK9FK6Vlhv8ASR0JZmO31cfCyPjSp4=; b=tDV//G2wlThQ4n 1lfEV4Szvzc1nxXXzGHDYdpc6qIekpwk5QCn/SNA3sAN6gIw4OZR/y0LtbmHDnooCRvjuDNEKmlVG 4A4LtSVu8ZOEf+3zApW9ng7XFmU83PE5qGbY2Pu7szLu5bP8u4QDFI8mRexViBLyk3/765xX3OZr9 MOie1ezGtKvzKzgGCUZj8jNcXnwm74hamz4RqmKNQfbm4Hwp/J8GF0BkqZ+155/uD1S05KcESrpIC A7+2i3FfIho4qtFC2bSXjL0Y3E0t4seBW3IZ2OtcgqxHVqp08xAVYJqWcBqL+wHO1BK0jdY+lWgoi lGHFrAJyMGQTr0Gz4yVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nqv4C-00DHfY-0i; Tue, 17 May 2022 11:08:40 +0000 Received: from mga17.intel.com ([192.55.52.151]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nqv3t-00DHVG-DL for linux-arm-kernel@lists.infradead.org; Tue, 17 May 2022 11:08:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652785701; x=1684321701; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XUGgIusaR1c/M+hdwMIEtCQbJlvmDStPf6Do24whbYo=; b=g0SGF6+1jLD5ChJNsN/azBflOJ9omaDJW09IIEkJHTpP7NqnBn62X7l3 um7fK98AdOShq7wLDsVCnm3pZwAAUSeJZU4k0VSDS4xlYmrMIO52gBIzT 8dGIsblieR2w2rM35Rug+quTv86jIzL2eKHSsXBb7YsAObSFyhgRhIpWx jfYsyTDmbcSPi8scXnuBrtnfn6hltkHXuZdL7OhfbGLOhLj/kt8G58w8F uiBw/vVIiwlopvQFYfPO+qzn5fDBttMcxvkh7aLdu0orgBx9RFrAxDBJX JJqw0SGjdoCPL2NrkXvas1PD3SsqoKIEYzYLvnvsNkKDW/wQERFwSA87A w==; X-IronPort-AV: E=McAfee;i="6400,9594,10349"; a="251658946" X-IronPort-AV: E=Sophos;i="5.91,232,1647327600"; d="scan'208";a="251658946" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2022 04:08:21 -0700 X-IronPort-AV: E=Sophos;i="5.91,232,1647327600"; d="scan'208";a="568831117" Received: from mtarral-mobl.ger.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.252.52.88]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2022 04:08:18 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-serial@vger.kernel.org, Greg KH , Jiri Slaby , Patrice Chotard , Srinivas Kandagatla , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH 7/9] serial: st-asc: Sanitize CSIZE and correct PARENB for CS7 Date: Tue, 17 May 2022 14:07:35 +0300 Message-Id: <20220517110737.37148-8-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220517110737.37148-1-ilpo.jarvinen@linux.intel.com> References: <20220517110737.37148-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220517_040821_530039_93F0DBFC X-CRM114-Status: UNSURE ( 9.38 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Only CS7 and CS8 seem supported but CSIZE is not sanitized from CS5 or CS6 to CS8. In addition, ASC_CTL_MODE_7BIT_PAR suggests that CS7 has to have parity, thus add PARENB. Incorrect CSIZE results in miscalculation of the frame bits in tty_get_char_size() or in its predecessor where the roughly the same code is directly within uart_update_timeout(). Cc: Srinivas Kandagatla Fixes: c4b058560762 (serial:st-asc: Add ST ASC driver.) Signed-off-by: Ilpo Järvinen --- drivers/tty/serial/st-asc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c index d7fd692286cf..1b0da603ab54 100644 --- a/drivers/tty/serial/st-asc.c +++ b/drivers/tty/serial/st-asc.c @@ -535,10 +535,14 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios, /* set character length */ if ((cflag & CSIZE) == CS7) { ctrl_val |= ASC_CTL_MODE_7BIT_PAR; + cflag |= PARENB; } else { ctrl_val |= (cflag & PARENB) ? ASC_CTL_MODE_8BIT_PAR : ASC_CTL_MODE_8BIT; + cflag &= ~CSIZE; + cflag |= CS8; } + termios->c_cflag = cflag; /* set stop bit */ ctrl_val |= (cflag & CSTOPB) ? ASC_CTL_STOP_2BIT : ASC_CTL_STOP_1BIT; From patchwork Tue May 17 11:07:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 12852296 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE2F7C433EF for ; Tue, 17 May 2022 11:09:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=z7ZwuDYCJetYWdO3FjeT1jd2/lCc0Rz7l2my/GrKPHM=; b=JT+LEcZn4K5dXh oAooqOdsFN7emTGkT3AhbJ+DI75lpj1zMsLr3M6H5FXvPeb1ujzEHmgoBoa43Jb8attFF0ZLlkK+w vCJBvZdxv4fFbk1MRb3Ti/PUy02Kdkh/2NsVbsgURp/MGdhVE5FYSuIV2AQD81EAC5EhVsjWm3L9w 72uECVNLE7wHWvVl+db5kSW2HjIgsPcIhWXsCqUcStjSo+VwN1H3JpEIGskCgxNyfXXej46oqB1jk uZ485FWWcvSXdC8dc+lJzGbHf/tHbveIfWwzwXTpDfJd/3tKBeo9rw4tF0QTeqYU6qrTNfFmjmP4u +UPVP5Hrgq5xFfVueAMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nqv4O-00DHqo-Uw; Tue, 17 May 2022 11:08:53 +0000 Received: from mga17.intel.com ([192.55.52.151]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nqv3x-00DHVG-II for linux-arm-kernel@lists.infradead.org; Tue, 17 May 2022 11:08:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652785705; x=1684321705; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B/wsivre0Bc6qlbjo3she/qQCDt/pTlKU20VjyLCa68=; b=BG6hiY8acAju7sKaUALXT6bROQfAhPXQg8r1SIvJaQdA4nXmzxftiTGg bwN+bZ2hiWKjz1RslGvGnPm7tJx0dysqDPeZ9NG37L7evUSLHtlYjPmY4 yOCoC7oIHq8emOFu2lBu4RYSw7GAVC+GQsSxxRLVfofo35v7K0ftFkGMK 24+W4POrTsGfH/ExC1Mj+HwowbTOtH9nKcnAyHgXrtLXQ0qd4DaVqaJwY 5718a5/J7lQ9LnDMYn5mqypqn1LEj1f34fFdphUNOo9u4MV3FHsh/TnJw wNKHDqxUWV13jxmrlMVwAJUHY7Gqlomd3KPPy00kNxknQWcaydO4D4cwD w==; X-IronPort-AV: E=McAfee;i="6400,9594,10349"; a="251658959" X-IronPort-AV: E=Sophos;i="5.91,232,1647327600"; d="scan'208";a="251658959" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2022 04:08:25 -0700 X-IronPort-AV: E=Sophos;i="5.91,232,1647327600"; d="scan'208";a="568831136" Received: from mtarral-mobl.ger.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.252.52.88]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2022 04:08:22 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-serial@vger.kernel.org, Greg KH , Jiri Slaby , Maxime Coquelin , Alexandre Torgue , Erwan Le Ray , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH 8/9] serial: stm32-usart: Correct CSIZE, bits, and parity Date: Tue, 17 May 2022 14:07:36 +0300 Message-Id: <20220517110737.37148-9-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220517110737.37148-1-ilpo.jarvinen@linux.intel.com> References: <20220517110737.37148-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220517_040825_663772_5F8069A8 X-CRM114-Status: GOOD ( 10.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add CSIZE sanitization for unsupported CSIZE configurations. In addition, if parity is asked for but CSx was unsupported, the sensible result is CS8+parity which requires setting USART_CR1_M0 like with 9 bits. Incorrect CSIZE results in miscalculation of the frame bits in tty_get_char_size() or in its predecessor where the roughly the same code is directly within uart_update_timeout(). Cc: Erwan Le Ray Fixes: c8a9d043947b (serial: stm32: fix word length configuration) Signed-off-by: Ilpo Järvinen --- drivers/tty/serial/stm32-usart.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index 87b5cd4c9743..3c551fd4f3ff 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -1037,13 +1037,22 @@ static void stm32_usart_set_termios(struct uart_port *port, * CS8 or (CS7 + parity), 8 bits word aka [M1:M0] = 0b00 * M0 and M1 already cleared by cr1 initialization. */ - if (bits == 9) + if (bits == 9) { cr1 |= USART_CR1_M0; - else if ((bits == 7) && cfg->has_7bits_data) + } else if ((bits == 7) && cfg->has_7bits_data) { cr1 |= USART_CR1_M1; - else if (bits != 8) + } else if (bits != 8) { dev_dbg(port->dev, "Unsupported data bits config: %u bits\n" , bits); + cflag &= ~CSIZE; + cflag |= CS8; + termios->c_cflag = cflag; + bits = 8; + if (cflag & PARENB) { + bits++; + cr1 |= USART_CR1_M0; + } + } if (ofs->rtor != UNDEF_REG && (stm32_port->rx_ch || (stm32_port->fifoen &&