From patchwork Thu May 19 08:18:06 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: 12854648 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 EF7F0C433EF for ; Thu, 19 May 2022 08:22:10 +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=AxP11uiV/BO4hQ d3426tM122n5vDUAfTA0KFBR/0hVOmzbOPuuosI0Rxb7JAf7sNLo4whWiJ9Cbvd527VOx02OlMxSU EF2kdthNQ4H30aDIJyjADy8wsOT1lO1P6hBGHthuQSNeU7HXdDQOketWJ+jkkzcw6GuhsNpu4w7fC sHjHWkJ37NOGZ5nYTT8xWBgkDjkfcn9iBQJIOMnAp+Wxqj83aMsp890MzjTPoVbIrLd5H8zEIWXWO +A0e/5+qFEc01szQkZnDETWp+0BZItPHz6jlgLeOzvfIJ8Scjk4FuiTg4OW/uUdcR0vP37WR/2W3I TTrk5Vi+0oMpxZ0y7hLg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrbP4-005mJg-T8; Thu, 19 May 2022 08:21:03 +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 1nrbMs-005kuX-HX for linux-arm-kernel@lists.infradead.org; Thu, 19 May 2022 08:18:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652948326; x=1684484326; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XUGgIusaR1c/M+hdwMIEtCQbJlvmDStPf6Do24whbYo=; b=XE7WkDtGUTr1KeUyNkJxVa2clZ9m/aZhayQq9B37g8a8GeJn/L31++Le OQe7eRVy+gJ+uu5Uoif3i8/amUQBpBMRgKiB/uw1d3y0amh1gYaJTVYsk 5k3RRqyEYZOqC5WRp71b9u+Q6KW4ssVRdPA2lvT7fe47xH2fMbowhsASt 6a0q+2XVs9i15WLAkQjkdB0qCyHF1IH2JWgpuf+XEO/nFNwrD9zoG5aVV /blg77Lamh/FHe4t/aP7yGB4y2RAu4AqmEAM3W8lT/6i21L92vAQi0g23 n6o15sJdZ5jgAvCHXopBElY2LGfdrEGrVcK6shjS2B8KjCeAl9eMFwf8g g==; X-IronPort-AV: E=McAfee;i="6400,9594,10351"; a="335135314" X-IronPort-AV: E=Sophos;i="5.91,237,1647327600"; d="scan'208";a="335135314" 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:46 -0700 X-IronPort-AV: E=Sophos;i="5.91,237,1647327600"; d="scan'208";a="598431493" 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:43 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-serial@vger.kernel.org, Greg KH , Jiri Slaby , Shubhrajyoti Datta , 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 v2 7/9] serial: st-asc: Sanitize CSIZE and correct PARENB for CS7 Date: Thu, 19 May 2022 11:18:06 +0300 Message-Id: <20220519081808.3776-8-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_011846_680316_CE6E1611 X-CRM114-Status: GOOD ( 10.18 ) 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 Reviewed-by: Patrice Chotard --- 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;