Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp443177iog; Mon, 13 Jun 2022 06:06:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwauM1qOb7BJ5Bg0LPG/RMnoe3VvzQmoU3Uhcs9kcL9Fxu3ttGb6vWbq1TaygxYbHQqZQ1U X-Received: by 2002:a17:907:60d1:b0:70a:f154:e3c9 with SMTP id hv17-20020a17090760d100b0070af154e3c9mr50251225ejc.376.1655125590599; Mon, 13 Jun 2022 06:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125590; cv=none; d=google.com; s=arc-20160816; b=02Qaolpz34KjAwBKZqGZmFBDjPLovxM3Ve0bz1xZXgjnBb2fY+TraJVbySSJ6m9MdT gHd0nbdXm4fLNR1QUs5kwGhrPDGeSMU5S2kN+ng4pfxgi4a1mczxiJk7A6QWiVhP2wXY S3EQiZ6yiI6zJskcN1W7z25ZmfQ+QWDiVf14/YlLda/6MVVT9azfDGynErr8ceJRGEgz pFHHVP5FO337MwSels++D1ZLZacOg/0yvRmruifnms4GCpdsLfwRENRRjfHPl3nxL+L+ r6SVq2HAnR+n3Og9Ozkm/YAFruclmvaNGV6eQA/BVgusKnByR3rCYxtQKHECSEqceT9Z KnXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sxvq5QU6denX7NrYF2A4n/EYA+YygCv+xVQedCs8yH0=; b=nniW7eHx0IXFJWv5mqn5mtbQ3ksG4gwV8Rt0PcrmxJZFtgl1rOYgWk2lfj/a8vv7zz gTwB5pDDbe5CIITPiHyY4fBlyx2dZr2ywoMAAr5apkEENXhZczSUUelkiW7CrLQG0tI5 SZK5Mb4uXlrk48zMkW0/g0R3K5Y7/vkUTodtxiWJnGG8TXauNB5OFKMdvjQMEP0zGEdF EWT87gMIb+IAKEYuFVOTQ4r2gNLwC0HbeCGc1v6i/nzR/NKCj3TdwCvcqSoF/fT2nicw ELP1yBfMr0E1zky05mPh3+hoOyt5g976TWYNGaEyUzN86VQUR7yExqFNnFTiWPlRzzxW 4AJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aufUp5vt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l22-20020a50d6d6000000b0042db0cc3333si7033584edj.149.2022.06.13.06.05.54; Mon, 13 Jun 2022 06:06:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aufUp5vt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354937AbiFMLkB (ORCPT + 99 others); Mon, 13 Jun 2022 07:40:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355194AbiFMLaw (ORCPT ); Mon, 13 Jun 2022 07:30:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B95754163E; Mon, 13 Jun 2022 03:46:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2FC0960FDB; Mon, 13 Jun 2022 10:46:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3861BC34114; Mon, 13 Jun 2022 10:46:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655117207; bh=tuQcfu+zbguBQ/7UQ1lU54Mu5zeYCCxE/hFVhC/tDlU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aufUp5vt1f8QQvXyx+fRgDNcNhmwMQV6SEIblkqTRxvx3KiKuUbR6uAriWWLlegYp vSa+53Anq0e/ZTVF37Kh2h+sjwvklQdEVqALznJ2rP5Z1Fj/g+OY/muW04s0e7tgrG FxihbZZPUH3HphvvL242G36GBcLkXPcf4hTqhtus= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Erwan Le Ray , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Sasha Levin Subject: [PATCH 5.4 314/411] serial: stm32-usart: Correct CSIZE, bits, and parity Date: Mon, 13 Jun 2022 12:09:47 +0200 Message-Id: <20220613094938.159015942@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ilpo Järvinen [ Upstream commit 1deeda8d2877c18bc2b9eeee10dd6d2628852848 ] 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(). Fixes: c8a9d043947b (serial: stm32: fix word length configuration) Cc: Erwan Le Ray Signed-off-by: Ilpo Järvinen Link: https://lore.kernel.org/r/20220519081808.3776-9-ilpo.jarvinen@linux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- 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 d517b911cd04..d5a084ffde89 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -745,13 +745,22 @@ static void stm32_set_termios(struct uart_port *port, struct ktermios *termios, * 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)) { -- 2.35.1