From patchwork Thu Sep 28 22:12:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 727555 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3B12E743C9 for ; Thu, 28 Sep 2023 22:13:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232586AbjI1WNy (ORCPT ); Thu, 28 Sep 2023 18:13:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232552AbjI1WNw (ORCPT ); Thu, 28 Sep 2023 18:13:52 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B0CA1A2; Thu, 28 Sep 2023 15:13:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1695939214; x=1696544014; i=linosanfilippo@gmx.de; bh=mLPlHXBVRwexjH0Cj387VLbBgxjGGRTQWXTD7dFXyMo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=KQLdbtXKMqmvGK1Ic+BlRFgjsdhtMa+SeK206YXzV9aLWtvVG3MwcYgjKoUQbdH/5H+HEPQ/98h 1f1UIEEaRq5EDiw6QmnAWVRBvcQx68gSlSmUTr/UkFn0TcTKQULUDGuMPzXKglAf0dLIKKvUdQHDF lXFnkYn/j4gO3Fitg9FsTeqgd9n41FEoFphuA1tv9qHepmeadFE/N6F1Fe0Z3j2cnRwIEKtQprXWs 6ZG9jcFkQoEylmIWrz5ceHC8/f0HNyM96VfoJZ0Hu9h2jSCpuXAKuJ6O0qPjNZn34ICO116qDw5xu p7of6bPxWU+UB7SWibAFzsQrMnbBFOCVIIvg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.21.41]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mr9Fs-1rOqb53LEM-00oBVU; Fri, 29 Sep 2023 00:13:33 +0200 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: shawnguo@kernel.org, s.hauer@pengutronix.de, ilpo.jarvinen@linux.intel.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com, stable@vger.kernel.org Subject: [PATCH 4/6] serial: core: fix sanitizing check for RTS settings Date: Fri, 29 Sep 2023 00:12:44 +0200 Message-Id: <20230928221246.13689-5-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230928221246.13689-1-LinoSanfilippo@gmx.de> References: <20230928221246.13689-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:q5g0/t22Us9cn/lBgY6QmJyAiEQaNgtDtxjK+YvBOStqaS2nDfQ zMcTJuIMThPdRFuVaW1gtGcUHYDcWQvKrpC6sbHrpdTc/V83oLE6S/gf+SZ0WT8FwTubJLA AK73xikeMQpfk/RPyTmOERBOOoOQ2mVVMRJMrA3y9kR1A2XLWdNRW+68nf0BpeantrkOKqd HzcieTLxxlfeczVfyRNjQ== UI-OutboundReport: notjunk:1;M01:P0:bWWTFd2uhgo=;AAkMwugWAP0QngTop9gN+mtLifq oyiuk799766XqgO1K4PbKk23jcF3B5UPyv7QojPxbW84dCERYBzE82tpJ2XRNJOQTiq33W6uP Kx4lAHLq9tSkIDhtZI1xZINRU/aUpmv3x0kv8cp+zWk1BZeAQqfb58pFZm/h2h4SDCVObX/xO NCEw/yQjvvsLFuGV4ggzxESWWrLboDBgfdRmzeu1iMSzZaXNJcWSFv+3o7VldANvdjCkCBPq/ IWdbDI/zo8tQHvUaSkeARUL69JhN5kD7+ePl7gf8lullnbfeFZtwai07MJv5sKWqH780ZnXSj v0bQ3TUEKZVU7EH4g3Z19bMO49QcV+hdKI934bbjfJbuhv/1lbUgVLD/uTSMLHkiv+U7kbq/E pBF56nWaK+So+UhfZnf8KsRCqFYHdKG7boemqTncZZaJ7v1cqC/fhmjb3xS1DB5/dEn4W6pwy icTY2jlHJokKpaw7JX222AdC5uvyf1dPGXrrrSep0JsmQGU1ltFfcmH10I1KsOT6/hrNZetpR IxGm/3w5odmbxEJw+SVJwFsFAaz/NRodQdT4aTtG+mK/+g+ydEdYu4ojdNw4kq++SBW9tl4Z8 E2avaKu6wq1+mIrQjzjXTtsGodmjX2fOcEFOI5kbLMzD2mDLDAznVWq8YyfjK0LNGMD1wMlwe j5EJsUxowU9Q1r8UEtFKDIIgpUfnmtv8uSIVQUvHnTucjg/nfwF5WW2yEjLf5+TXbQ+XhIVK0 waMoQgJUB4KhvgCfJfxxhpk+D8JfZer+Bff0qEatMvwwxqVggY+SsGwTjaYbi2msKxl/dxZeR QzrM55e/IgDbEDWL5hQysiHe5Aet7imB+qyAFBQvMDTN1VV0wXCaCC1i3U/syBRf7PQI846UW lPMzRTeKhKDg+mmdMrQQk+A0oKcKcBifty4FS3PtRc4Pg8Dv9oRWNBDLIj0KmW6CKcvuNDfwV irpBEA== Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Lino Sanfilippo Among other things uart_sanitize_serial_rs485() tests the sanity of the RTS settings in a RS485 configuration that has been passed by userspace. If RTS-on-send and RTS-after-send are both set or unset the configuration is adjusted and RTS-after-send is disabled and RTS-on-send enabled. This however makes only sense if both RTS modes are actually supported by the driver. With commit be2e2cb1d281 ("serial: Sanitize rs485_struct") the code does take the driver support into account but only checks if one of both RTS modes are supported. This may lead to the errorneous result of RTS-on-send being set even if only RTS-after-send is supported. Fix this by changing the implemented logic: First clear all unsupported flags in the RS485 configuration, then adjust an invalid RTS setting by taking into account which RTS mode is supported. Cc: stable@vger.kernel.org Fixes: be2e2cb1d281 ("serial: Sanitize rs485_struct") Signed-off-by: Lino Sanfilippo --- drivers/tty/serial/serial_core.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 697c36dc7ec8..f4feebf8200f 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1370,19 +1370,27 @@ static void uart_sanitize_serial_rs485(struct uart_port *port, struct serial_rs4 return; } + rs485->flags &= supported_flags; + /* Pick sane settings if the user hasn't */ - if ((supported_flags & (SER_RS485_RTS_ON_SEND|SER_RS485_RTS_AFTER_SEND)) && - !(rs485->flags & SER_RS485_RTS_ON_SEND) == + if (!(rs485->flags & SER_RS485_RTS_ON_SEND) == !(rs485->flags & SER_RS485_RTS_AFTER_SEND)) { - dev_warn_ratelimited(port->dev, - "%s (%d): invalid RTS setting, using RTS_ON_SEND instead\n", - port->name, port->line); - rs485->flags |= SER_RS485_RTS_ON_SEND; - rs485->flags &= ~SER_RS485_RTS_AFTER_SEND; - supported_flags |= SER_RS485_RTS_ON_SEND|SER_RS485_RTS_AFTER_SEND; - } + if (supported_flags & SER_RS485_RTS_ON_SEND) { + rs485->flags |= SER_RS485_RTS_ON_SEND; + rs485->flags &= ~SER_RS485_RTS_AFTER_SEND; - rs485->flags &= supported_flags; + dev_warn_ratelimited(port->dev, + "%s (%d): invalid RTS setting, using RTS_ON_SEND instead\n", + port->name, port->line); + } else { + rs485->flags |= SER_RS485_RTS_AFTER_SEND; + rs485->flags &= ~SER_RS485_RTS_ON_SEND; + + dev_warn_ratelimited(port->dev, + "%s (%d): invalid RTS setting, using RTS_AFTER_SEND instead\n", + port->name, port->line); + } + } uart_sanitize_serial_rs485_delays(port, rs485);