From patchwork Mon Dec 25 11:35:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 758366 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2052.outbound.protection.outlook.com [40.107.7.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5941C5101A; Mon, 25 Dec 2023 11:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=kunbus.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kunbus.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=kunbus.com header.i=@kunbus.com header.b="q3qNevDO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LpC5wcYTiAAzADkbjRVWnNVIHJ3oc0NjNXAxyD+DQhs2kPHX7YKYBbMbWsca034lTmVRqTUVR4vdlbH03vgjlMVqk7U/AJcnmzXDpxUXR1j3Qzb2iOlELyY9eEQRCz05cvJtOgA5a/VPn8Xct74ltvtTGEPGRD/lMMw29MZVs39metjd6MQt0pLD+nfvz25TN8TKEXMBY85pBis/mh95+LxDwr0tKq5ugh0S/0OnWz2D6pT09H6AfkETrdYFOfa4+bzn324cHB3FkdznJkl0ZKj69Enrvww6HH56fN3XVWjImRsHMx01Z+SdfV4du/Iot6SshQfM4k8lbi5ak8Eylg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zrTCdaXp4RpigukbEw/E4R9h20jHnCpK5qa1aIze2JA=; b=RX0VOlqsxwAelafUxxyEz52H7AQErRF+3uMufOn3TtuSLIn+XzX0wSLkByfP5cC1yFg9qdXYBbrPTGcd5JLZ3tKgGJaKV/hTmfZjBfTt/oblDmMXbSIRiqXgIXjWyuqbTuChryJHanpXiLMJjcmq6vJoVuqLqsjhaGiQg4Hx/6zjmJa6zu8tNlfNvvwrxzolGzB5INkyt/aibGRK46KlDDKON/o/Dem4fA8Is0qTsiwsRBjv9LuHT7vG41wvJa7/IAMpL4s8ZHYNH0tdRbITA5gYSv35M/6yJnXZXsmW9+0M0n3jZAR6ksZLEW9Pl/7VO1oZcWZ0P4vYiiNDVwaaTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=kunbus.com; dmarc=pass action=none header.from=kunbus.com; dkim=pass header.d=kunbus.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kunbus.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zrTCdaXp4RpigukbEw/E4R9h20jHnCpK5qa1aIze2JA=; b=q3qNevDOoMSWtTdU9thGwvjR74myYQvod685CZebiuKxMBGj64UkeTLW+dBdZhI2pAYoN4F/bRXBY6oghXRxNbxDLYQgnm0Ft8QzeLqElzymoCTsWIRU2m7TpKlu3mRTTGugscoEYc1DCKQl7Z20NDueTo0EuGI6nMzc9l1+2Uk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=kunbus.com; Received: from VI1P193MB0413.EURP193.PROD.OUTLOOK.COM (2603:10a6:803:4e::14) by AS8P193MB2061.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:44d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.26; Mon, 25 Dec 2023 11:35:55 +0000 Received: from VI1P193MB0413.EURP193.PROD.OUTLOOK.COM ([fe80::653f:d0f3:e7f6:8c06]) by VI1P193MB0413.EURP193.PROD.OUTLOOK.COM ([fe80::653f:d0f3:e7f6:8c06%5]) with mapi id 15.20.7113.026; Mon, 25 Dec 2023 11:35:55 +0000 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com Cc: u.kleine-koenig@pengutronix.de, shawnguo@kernel.org, s.hauer@pengutronix.de, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, cniedermaier@dh-electronics.com, hugo@hugovil.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com, Lino Sanfilippo , stable@vger.kernel.org Subject: [PATCH v6 3/7] serial: core: fix sanitizing check for RTS settings Date: Mon, 25 Dec 2023 12:35:19 +0100 Message-ID: <20231225113524.8800-4-l.sanfilippo@kunbus.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231225113524.8800-1-l.sanfilippo@kunbus.com> References: <20231225113524.8800-1-l.sanfilippo@kunbus.com> X-ClientProxiedBy: FR5P281CA0055.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:f0::17) To VI1P193MB0413.EURP193.PROD.OUTLOOK.COM (2603:10a6:803:4e::14) Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1P193MB0413:EE_|AS8P193MB2061:EE_ X-MS-Office365-Filtering-Correlation-Id: 56ccb621-1b1a-4440-85ea-08dc053da6ff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tKYCaaPah3qoqQ7coyRN2F484bUDQK7mx30jI9/oUyi7kFetL17EqK5Pqwq7/Yw3x2+/lyT8XX3n9UM/P2h/rjscdBLX/sFBy1Qubs7JmZACkLs/gQFiorIoqBWSJ9NrIwEb112JJqpdg/Ot1eYKwtoLEs8ap8nKaykPZ6URcrZuDtR/AsGIY6/cCiovED8fAhfUIHSTgr/bZcg4tgwIGso84qFR3vUf+0jnohmxazrYRBAkMNTkceNWubpe9nb09WsoKrpTlYP/ljEjN0HkkYyurYjgYfLCHlkAHycR5iUI2y0odaPwwjxPCQR6SRh6dXp5yUX+Z3wqNbcCm3RHow+arR5ghwp33clpOWmFfM22Tdrt65SoyBJX1cQGbJKXKNIEFCovr3lUG0ztDiEHf45HsxqbxkJcv1YtkuBoS/zQmgl7GEfN1REspYDcllweM8PZgMMYwC7RtIhh1NgP9WpQwxebBMVq3YquN5VMLCAwCKdkkUuCsOZvXy0YY98Vfl8YP7Ega2P9hxbrQ1jvdqVn0Duk7ITXuLen9WAYZtMgSzXg6ja6xvCbVLQWcPTi X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1P193MB0413.EURP193.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230031)(396003)(39830400003)(366004)(346002)(136003)(376002)(230922051799003)(186009)(451199024)(1800799012)(64100799003)(2616005)(6666004)(6486002)(478600001)(2906002)(8676002)(8936002)(5660300002)(36756003)(7416002)(52116002)(6512007)(6506007)(66556008)(66476007)(4326008)(66946007)(316002)(66574015)(83380400001)(86362001)(1076003)(41300700001)(38100700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?AAkkXEHU+G0A4C8Ju1eb9q6FtxVa?= =?utf-8?q?mhX4Vda++W1O3mwI8ed64zFfLnRKFeiQVrIf8SUb9gNdGLZkwjN62qwXO3we0WoRJ?= =?utf-8?q?bDhD7lh28lxP2spwFYKFWpUtnnA5RxgnHXLGUV/38gVa/JgwA80DpX4ooNjCXVpIE?= =?utf-8?q?FF6xEj5vEH9v5XZV9Z4XkoGFZLyv4Fs83Y3NX+bWeF5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Ep8ZAVrlt0u?= =?utf-8?q?VBzSvKGns/7qiUfxYHUJRZVX3xKkX3G03YWr/UnIijmnnDVtsEF3gXPKI6+PXRwDj?= =?utf-8?q?SuRsCrwjKBTCNcrWqo5sHrjrN8NXPKdxoiQyX7oWfKBau4ZhUmL0jSq3dahjuraIB?= =?utf-8?q?2dR+hvcXeigWXJRcdhaUuVPLuSa0RLAjGGJcN2ZoIAe+8knZ7vC9AZa1/1XRR7HW5?= =?utf-8?q?0wPHQg22acAJwF2FXzhNyNpYUIUPbaMBq9L0fzaKrL2zQ8/PBiSTPGnL+OiEx1zds?= =?utf-8?q?EMIfwlNvTJFlhH0T6lZ/N4p/MQmirSAkrkDRxrokUmQ/QnO1zMjAiCPjY+EXThh8Y?= =?utf-8?q?2wfdlVUQl7B1XbWNFhBqSMM0YrqhTid2jxpcaFkJ+APXCaP4kyXV/vKsX/Sosd732?= =?utf-8?q?JBYxSjkk4sdSwKM9SW+a56K6SyyUGQORoJNbugRV0JRMdfsAWtMr3hTHa50u+drhU?= =?utf-8?q?oIo4sSxuc7h0y8Uyjsa+kI3PsZklZGAEPHepLd/iv378N+u977+IOib+dj43QJGL+?= =?utf-8?q?Z+vJF1LDhTU?= X-OriginatorOrg: kunbus.com X-MS-Exchange-CrossTenant-Network-Message-Id: 56ccb621-1b1a-4440-85ea-08dc053da6ff X-MS-Exchange-CrossTenant-AuthSource: VI1P193MB0413.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Dec 2023 11:35:53.3842 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: aaa4d814-e659-4b0a-9698-1c671f11520b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lrewWoKd3gv5sQ5zK3ViorQwpYJy753VNrJaXDkRlCld3NkOkIUt0QtNLVcF7tuJhF7ih/twgZOJgZjMVpgBwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8P193MB2061 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") Reviewed-by: Ilpo Järvinen 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 1204102d7162..f67fb6a04983 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1371,19 +1371,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);