Message ID | 20240105141153.19249-4-l.sanfilippo@kunbus.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-17908-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp6245515dyb; Fri, 5 Jan 2024 06:13:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEBF4mzDxeMj1TTfvWD1ZCzp8Z7DviqqMKrcxdG4OtLPr/8Nadis1g42ETaU2pdRYpr73pv X-Received: by 2002:a05:6512:e86:b0:50e:27a9:167e with SMTP id bi6-20020a0565120e8600b0050e27a9167emr1225507lfb.59.1704464024448; Fri, 05 Jan 2024 06:13:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704464024; cv=pass; d=google.com; s=arc-20160816; b=ZHt7/gjfP360ds3y3CmVJLm5mD5l4SxBd0i4WlhcYFqEvtI6UQCp2RLd/Hd8yX20gp nol47FryQUHxRkjPHpMS88aizuDQ3OY0U2KLNr1dQwCBC/CCzTYZ60RndNXkWnw4PhlG UyoQ2C4A+fFrLMvU98uam/GdGEAnKPiIx6m1MSWCk8PF/DeHtD9/T01KXvXD6g1h3Eqs oG7qWL5T4an57JsNu675ZTI34yDdLqwma9q3pDAxzWk9OXKsh+fmMPbtI1+l/7NX8PYp Y/KUbmHkB2+LOYRzDD5gfVwb9+fN6ohWV0iMO9sG1x9pFak3+ZnF+LecYWMald8jq8Ln If4Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :content-transfer-encoding:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=zrTCdaXp4RpigukbEw/E4R9h20jHnCpK5qa1aIze2JA=; fh=MN/bkHGu84ooMMTgCiXP1oFxiryoF+JDoK0S8hA26Mo=; b=Mc8M77fx88uR4y8bnWiI2RF+6tdiuxCnYGaVJY4NLUs5EKH7rmUeiyEn2GoTkpJMv0 7xuYGSy8q7ejT3+V2tuKwXz7tR/XFWWdBt8MSCKx4tU9FAIcnjtUSn2P53wTZpYzP/8o BPyfeoTHCbiw3+W/dKM/wvpZ0JP/kYVM9+9+5thYTy5dRFCxbkTNzZBtKnh7P58KckVu EI2Ih+t+/0kBsKX2VUPyUof4+e322EKiD/IP/pOBUeQlzm+yRQ8MXJ/txRCCbeXAbLaV XFtLFQqc6inw8WLJEUw1EHsuh46JtjT9loiS1b+5Iu+VyPKp5bQGsN+quJgaJzOqlx+u dSEg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kunbus.com header.s=selector1 header.b=J4oShjNu; arc=pass (i=1 spf=pass spfdomain=kunbus.com dkim=pass dkdomain=kunbus.com dmarc=pass fromdomain=kunbus.com); spf=pass (google.com: domain of linux-kernel+bounces-17908-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17908-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=kunbus.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u11-20020a1709060b0b00b00a28b300852dsi595318ejg.928.2024.01.05.06.13.44 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 06:13:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17908-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kunbus.com header.s=selector1 header.b=J4oShjNu; arc=pass (i=1 spf=pass spfdomain=kunbus.com dkim=pass dkdomain=kunbus.com dmarc=pass fromdomain=kunbus.com); spf=pass (google.com: domain of linux-kernel+bounces-17908-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17908-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=kunbus.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 106771F239F4 for <ouuuleilei@gmail.com>; Fri, 5 Jan 2024 14:13:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 78EC62EB06; Fri, 5 Jan 2024 14:12:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=kunbus.com header.i=@kunbus.com header.b="J4oShjNu" X-Original-To: linux-kernel@vger.kernel.org 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 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 <l.sanfilippo@kunbus.com> 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 <l.sanfilippo@kunbus.com>, 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> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: base64 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-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> 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/XUxXcOcUbzjojPWOEFkIrqNghOylWS27+J6z?= =?utf-8?q?SK7DcYoLo7RRGvDS5N1bfX0NFeTAJDoaCEFrPLRhRKs6NLXbIBMa0LgmtD6yiXmso?= =?utf-8?q?ntdT33T+oJjlgbgq1bQHwuFMf3O1ZozrgDAoOJo3wkOWISeVMlyhCKeaieTBrolYP?= =?utf-8?q?ur4MqW2rnoIOn542J29xoZEapJ5VA4shGGVNPyezPC6DO5/Z6ybX/ghWnrHxqbfHH?= =?utf-8?q?tHCPwY3YrTpUgI0XTibzDri/d2iHvn7TFqLPgbYka8qHGP5wPOro9H3v4Rfm8o1oZ?= =?utf-8?q?URJZxnjUXJ2NEMaXKDcV0KKSzcH61VQGuwEnSx2QC/ZYMph7IKFvdNp4epTIFvFKk?= =?utf-8?q?+a3taraS0BlznPzJB20cQkxQNUQHyaLWadDFCF5Q9uUDMWKuteDQPulq+5ldd2vU6?= =?utf-8?q?AaOI+/sZ4lO7Zm44VOBuzKy5bTNtWMtUr8ZsUB3FzyeY5ZB6lNXBvKcFuf1jze1PW?= =?utf-8?q?msZ7vBfyDnHFEDMcuiywoC89QBWWSWxOI3gBNY2Fy52PvOWUqxMWju3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gao?= =?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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787260068934377321 X-GMAIL-MSGID: 1787260068934377321 |
Series |
Fixes and improvements for RS485
|
|
Commit Message
Lino Sanfilippo
Jan. 5, 2024, 2:11 p.m. UTC
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 <ilpo.jarvinen@linux.intel.com> Signed-off-by: Lino Sanfilippo <l.sanfilippo@kunbus.com> --- 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);