From patchwork Fri Jan 5 14:11:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 760404 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2060.outbound.protection.outlook.com [40.107.22.60]) (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 4364A2E40B; Fri, 5 Jan 2024 14:12:22 +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="J4oShjNu" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HOMA1eUQsjxYQT73u5GF3XbLSTqiO+/28/a7MYwt2EmSlUlD6DausqaaYSykPlCspzAQpTqdvOQnI3luMKNL/ru97xG4g86d4qEf+dKleCobTpYTleJY/EjeqwyLQVqkYZhxygQ2xqVjsnweFKISwKOsjpEjOGvZzqOmR3l1LD5alB72yfzgIBOsfwlhI0R2ORRCnPSX8kSjb3r8Z7CCtKIymq14YeojqqJPu3f7pkba5hRG5JEP6Sry2jFOYDda3/5zHaOeRQfdnmCrEalAFhG5ScJ/KI+gwYwxx/Pm5+qzQlTVRL9gX6By5YA1c1bkJJ5WYsRGJMYkQgXMYqY03g== 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=WCA26vCwF2ZupWSgm09Gh8MejcDVcntyi0U4UJSqGjr3cUpWU1JR5b4By8y8YX3Hnct6oA4T9D3ktshJnZ9pf7EMVUltbetGTLJ0Hv+wI5q8Sr7+N3hi8lz89qvgiWyUqusutTnBPlQgAk8cD2M+nDH85ioKbA8de2A2qv5rd4eRfdsVyqBgkzZNK2Vk2bwB9jRdAu/hOygbREpPphApAufveNVbFm9jtQEMxIQWJM/82Z/aFGU8vAVMJHOv01ElIZ3wbVTzAdudd09v+Q8JIZI7zsD+QkMPpCeoGBH7mZViiHdcA+Hw8VSmSMiuxiz+VWLLFtGW/8ndQtdzLE7XpQ== 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=J4oShjNuAeUBDVNh+HFp0ApML6KsJdZWsCvrZaI0fyjwzQ/Kc4kd5OgV0Eg+uIcBBLpdRH/SHiUOev68/zLJ25dpH9NkFcaQSj9Q4d7Xs7BHMkfQ/B5AmuAkVossf5cQqm5Iu45GpE6EVXDGAeK4SS4JJs5imKEcDXszOzOu1KA= 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 AM9P193MB1538.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:30a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.16; Fri, 5 Jan 2024 14:12:14 +0000 Received: from VI1P193MB0413.EURP193.PROD.OUTLOOK.COM ([fe80::67b0:68bf:2582:19cb]) by VI1P193MB0413.EURP193.PROD.OUTLOOK.COM ([fe80::67b0:68bf:2582:19cb%6]) with mapi id 15.20.7159.015; Fri, 5 Jan 2024 14:12:13 +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, m.brock@vanmierlo.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 v8 3/7] serial: core: fix sanitizing check for RTS settings Date: Fri, 5 Jan 2024 15:11:49 +0100 Message-ID: <20240105141153.19249-4-l.sanfilippo@kunbus.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240105141153.19249-1-l.sanfilippo@kunbus.com> References: <20240105141153.19249-1-l.sanfilippo@kunbus.com> X-ClientProxiedBy: FR4P281CA0327.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:eb::11) 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_|AM9P193MB1538:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f9d0a11-92fb-4370-5141-08dc0df850c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Npi7DARQ6mcOFrEijT2MqAzd8f2HH75iT4+1Hi/9x9ukllogheVpq7RjaErlbakdwpq40biLKCp2Sf8PuNodd+0WXyi555r6LH2iYWWyBBe3q35E+7lhlMDoanUBrOmaaZ8SvK6feqQ8EgeGOSghg6GzjZEHb/n/fJ5KRj+gNRrcQflS1kPUl+Wdkx77pizladznaLWgX0kdhBvPAwjng2h7VLAk7JroOfY2TjbqOSR4WyvtwXLJ3C4HBs6B+k0E6HmE5I44mcgA9ONR8vrADUPigj3J8LQYsE9krmnO7dtYPaes4cefwrhsPIt1Bf3EN5FAUojDrmaJUb48KhEIzqoCzSjVok/QK+dNQ8GuX4e40ofuASpv8Jrn44TcsK6prl0RImsKvc8UrhJivGQvSEYZMWINSIdVl2dKBToampFJsgdQgZ1gbcuFAUTwWttwP/iDzUii63rulOiLw+CVMgums1JMCaHeET0QmLqYB/qOGYEv/XNuGHQD6TXI8pJWQOQGcO1VZFvBXbkU47tVe29rMWW5MEGneCYHNw6swoaayBs+p8BVxr2bOZOU6Sbt 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)(39830400003)(376002)(136003)(346002)(396003)(366004)(230922051799003)(64100799003)(451199024)(1800799012)(186009)(36756003)(52116002)(6512007)(478600001)(6506007)(66946007)(66556008)(86362001)(66476007)(6486002)(83380400001)(38100700002)(66574015)(2906002)(6666004)(2616005)(1076003)(7416002)(4326008)(5660300002)(41300700001)(316002)(8936002)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Sz7Owekoqr4WMELE08KHY5ljcgH1?= =?utf-8?q?n2oO5Vq+qo3w3ocBpXw10DcFsklbefz3wCZfVfv6Lxf8PQ2Y/UCHf1us83LJmrTvm?= =?utf-8?q?3TX/kqMAZSV+1jr1KrT85+peal20s1uUv4ex+/meYwPnO+TLxkKLhcxkzokNCTx9d?= =?utf-8?q?w4ZkaECyQvf3d+trCSnClDau53FB/XUxXcOc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ZnXcym48Kf5hx2VNQ2f/ffLulV?= =?utf-8?q?meDjAJDfhMcUC3Hu6T2JvNr73CP0yCvCdEgsABqdYEx+mCGt0J294DL43hBOjZuAT?= =?utf-8?q?1sH5C1kvbVHp/tXuL4j+XW59+zyTjZpyhryimRhNhaKKv3J28kHGzYHnD1eId/+CQ?= =?utf-8?q?ZhK1zvGQAe+vQIfILrXnF79GqVNH81L+y5GeTvvjUzLEz3GnkJBDR7PQadfoM84Wh?= =?utf-8?q?CPJkQCXe/CEIsuocZCQCgz5ZoyB7BxpkYnj5AS2SD/eLVflQYtuFKZYDITjKaJh9h?= =?utf-8?q?R1IpcMRBQReMNHaH1DK8cyB08ny3F5V/1dqN7ZPKeZllG1nPNPila/kHWH559W30D?= =?utf-8?q?fUe0b9OqRCQlF2UzmFlf+gsIUTGC2KoEj0jIGR2cmwVYZA+yIW2SVCMP44guMuXA2?= =?utf-8?q?tgQAY17jCFFJAJUe1Y+t0ax2yhw2axfykET0Whqc3rocZz2SiLyW4Ofuvik3k9IVY?= =?utf-8?q?d1VCfUudGkZFN0kzc5YWkmGPnZ7yFwE7oL2W0W7ZdGeGxU4PqybmhCHKopbdZ8gao?= =?utf-8?q?0ry5kB04/Wc3PVmw0YtIYbeFO+06r2eYA=3D=3D?= X-OriginatorOrg: kunbus.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0f9d0a11-92fb-4370-5141-08dc0df850c5 X-MS-Exchange-CrossTenant-AuthSource: VI1P193MB0413.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2024 14:12:13.9152 (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: iKs109ZPNINBRfKQpAiQtq22vD5U3Gfyv+53ZPp+1rvgkIPbumGcRhoYqRc6tUoODLVO3sB1oxPEGrEmFWRbSA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9P193MB1538 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);