From patchwork Thu May 19 08:18:07 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: 12854652 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 DA905C433F5 for ; Thu, 19 May 2022 08:22:50 +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=O6jYa4larPikRo k2NJpJbLpPFhjnubdeyWHtO1WgLP0CpWWiDckd/q2hIKE70UBL9nQ/cP50NSI5Oj8NrB2S96IAbsK 62jp1kkRuHvBVt9cmOoR9UzweInzxJa5EO+iJIA8M/0QnZNwsWu5HOAw4bblKPhzfYKXBODfoIqbA PavS4OC4wP8i90BW7jGYCIXsinaAhmCXAX/6ejPVtLLOE9RLyCjRI3ZVnVdxKZnAkGTVA1Z3rtjQI 8rxnkLFYfh4Dw58R/yTOC7EHTS6WHKnGvtIZ0G+a5T4LJ3sQOhOuINV+fi5htaXXzLrDwokKtwW73 wBdkY+vqMpAcOlnzos4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrbPi-005mk7-Cw; Thu, 19 May 2022 08:21:42 +0000 Received: from mga07.intel.com ([134.134.136.100]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrbMx-005kxL-9S for linux-arm-kernel@lists.infradead.org; Thu, 19 May 2022 08:18:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652948331; x=1684484331; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B/wsivre0Bc6qlbjo3she/qQCDt/pTlKU20VjyLCa68=; b=HNyAf1H+vqExekLL7Bai8APuHjC6T5E+fwz8gjwfT3BOT8QB+4Glozmg UvH0TjtX6eNQsAl5tLQeJzC2shMp0x0GckKMNSjK1VnZxniCi1IPPzSbs UjBLN03rteyyEyHYDMLvUPwePYc+jiYxXPerbry6c7RwKiQYp74XqScET 7E239u8rapC3Age2iw189AKhrR3gQyBMh9Lg0Pe7D0gIhNKCTOHzkubPb VFCehvIlCyHqXUk2+Alju7Qy/yYrnIUXvJNGLFGHpyDB+4XML336LTCL0 6M51ZkjNygcfTyC+/NOP2MRpDoKvysEmLZsxL3FxkUGv95l4/z+fEM7t7 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10351"; a="335135343" X-IronPort-AV: E=Sophos;i="5.91,237,1647327600"; d="scan'208";a="335135343" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 01:18:50 -0700 X-IronPort-AV: E=Sophos;i="5.91,237,1647327600"; d="scan'208";a="598431518" Received: from ivanovbx-mobl1.ger.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.249.33.234]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 01:18:47 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-serial@vger.kernel.org, Greg KH , Jiri Slaby , Shubhrajyoti Datta , 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 v2 8/9] serial: stm32-usart: Correct CSIZE, bits, and parity Date: Thu, 19 May 2022 11:18:07 +0300 Message-Id: <20220519081808.3776-9-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220519081808.3776-1-ilpo.jarvinen@linux.intel.com> References: <20220519081808.3776-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-20220519_011851_476569_468A6D83 X-CRM114-Status: GOOD ( 11.16 ) 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 &&