Message ID | 20231119112856.11587-4-l.sanfilippo@kunbus.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1604314vqn; Sun, 19 Nov 2023 03:32:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGOAectBwOForuwUakXnZffm1KWrqNZKKJMo7iIIIAY0Xb4S6xvhwFcYCa1Io30wAX9NMY2 X-Received: by 2002:a17:902:b417:b0:1cc:2469:f2ff with SMTP id x23-20020a170902b41700b001cc2469f2ffmr4977040plr.9.1700393575413; Sun, 19 Nov 2023 03:32:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700393575; cv=pass; d=google.com; s=arc-20160816; b=gk7Tluu5n/MALvJL1kI9ZYQFZZpm6pbsFUk8KL+c71euHYQHZEgXAirRWCu5zlNU8v B7MFIQ+ONgCaO9q5gkn/7q1xhkQvh4yUHp67Jks29zlV7DEonCagGxTz+tXBbgm+b3Yd vvLuSLw8UZFG24tv3Lhb28l9qEIAoxzTndgDscYrv/Eg2xIyvmctuxaagzzUAQqMNrmb iw9SXkrvh1mgA7eTrVrfV6uwOp9c0GcF8NiLAs8QBBJ8oNV7HxdpFuFPnCycoaCU8wEQ Rk/gPZ/GiEZGI7uddBQts3eiBolHS+tZmoFMtHuOpltmKkNC881inBMcyREwZcK/Se8e MuqQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6ZxcY2V8pvHHlMHg+raIYpD3DErsKilkTaqXyHGRn8k=; fh=TkiyChPg6bbF3HR9T06bpNLcepPHbldn/GrIZCqgMvI=; b=II5xnDEhjB45agHESsGFIb9ihBeipnzADw41Wee4+nVkP6PF2sVjoZEwOGymEkBXOo UB6psBgwUKKLraR67BK2FZ/4XIDZ/41L7vI+sBBOhXu03HWwqZ5NVFwUR0EZwtwK9wm0 2OzqN3cMpFPgRoYGaJ0deMhqn4hdxTsuKy02Mqu7FfbwkzZBvSsfOounqBm/98qLoBLI ViAB3ZjzyyZnWJiaNpCvc8LhhdyZqddAgCmtdgmeIialQ0sssxV6CH/8wBqOhamB3Xl9 C9xj8Cbbte9AhZflaBAjWWYgCRSXJfywBvtops7JUhcBSRI/1Ejg1aZP72jfZE0LYUGU 0iWw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kunbus.com header.s=selector1 header.b=WEpZYnYc; 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-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=kunbus.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id f18-20020a170902e99200b001c5e1c94588si5702263plb.550.2023.11.19.03.32.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 03:32:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kunbus.com header.s=selector1 header.b=WEpZYnYc; 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-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=kunbus.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7EB5E802D527; Sun, 19 Nov 2023 03:32:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232065AbjKSLcw (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Sun, 19 Nov 2023 06:32:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231898AbjKSLcj (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 19 Nov 2023 06:32:39 -0500 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2064.outbound.protection.outlook.com [40.107.104.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17DD044A7; Sun, 19 Nov 2023 03:30:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dU4UICB6flJUXF6E2PVbUV4OXfSjXfyKlGcnfFh9VagLv0tzHWiiqPOByzMM+YpAVdD8M0BJGhX39rcg3Lj3FR+pu0OxMl6w4cvh85b0/UlIOprR6yLpq8HNcpmUONRky8BAapkeCQfuoVzzkfld03JqFgSR5c/1vQXh60ZeLJUsj5nUQlLTOCQYaWR8aDieAMRe4BKjaAaQU9jlNc+EHGG9pNwQhCrBMq1u3MPLfauWZBQGK7qTN8nWZNKfWkPkcktg2YXvWpooXXYchpPWkv5rqAiC87xu6xiCE6GVUnwdENPPoE2w5eWEQmU55zRyaFcN4EL2KeHJrj8Aj10DIg== 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=6ZxcY2V8pvHHlMHg+raIYpD3DErsKilkTaqXyHGRn8k=; b=npHDLUtAh3Wvs0Ulwg/x4IBRfguzkwg6VB03CSh9jrsEHn9XU3fYXanzXX+JW2sWo2AMM55kZgFvnbxmthQ36my12MbbELM1G388SlncbF6aer6w+2goT9VN1jqAj+3iC89YQws/viLjELFehAXLy8YoSdK5uBzdqhQwuRX3ljCfYujIcG78MRipMNOasIUOnl4VFj31pS4VQJGa0wcI34eRayA8My/GLQL/5Mqk/ZA7PluyTTuCNBepZX/ofOowciIRxwq9AC9+KvvN8fatuzWe+WB9GDtIxZAC/XAhCyljH8sVDCc6F+LMDI+ZteDSUJHm83afmy6FQlQmR9Cxjw== 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=6ZxcY2V8pvHHlMHg+raIYpD3DErsKilkTaqXyHGRn8k=; b=WEpZYnYcNGG3RWiZrki9Fo42W8XXlb9JstMHyX70ACLczzVibvzquhnk+h7JGbU9hzEJaYpdjRTEzQj2TYrjNReNEksGC26bHJKiR5wIgeTo1HgyChwg9PPO0vl8hynTYXCafriukiDAFkKRgpxCuJtZPBRv6VL101ODiES9+vM= 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 AM8P193MB1060.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:1e5::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.26; Sun, 19 Nov 2023 11:30:00 +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.7002.025; Sun, 19 Nov 2023 11:30:00 +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, 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: [RESEND PATCH v4 3/7] serial: core: fix sanitizing check for RTS settings Date: Sun, 19 Nov 2023 12:28:51 +0100 Message-ID: <20231119112856.11587-4-l.sanfilippo@kunbus.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119112856.11587-1-l.sanfilippo@kunbus.com> References: <20231119112856.11587-1-l.sanfilippo@kunbus.com> Content-Transfer-Encoding: base64 Content-Type: text/plain X-ClientProxiedBy: FR5P281CA0007.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:f2::17) To VI1P193MB0413.EURP193.PROD.OUTLOOK.COM (2603:10a6:803:4e::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1P193MB0413:EE_|AM8P193MB1060:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d05352f-e67c-461b-edc4-08dbe8f2ddd9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +q8ospweDuzsc684eHqP29cq3Ilf6Oy4tYHZfv0HRnNu79l7raCC9iXZz9d08LbVB2B95NNBWZeDK0drnG/yX5yDgXO6jNE93SYY3MN/yFavoNo5eBjpkUu0f2R/D3ZzCsdMbVt9hb8/16EuKV2Kneu1qQyUC+PGZ12zv6w5chIHwVS4b/ywrEqG67Z331DeATLvQ5Z9pwNLmUOPwqsiBDuvHBP9JLfuHZ2wYhSmZVuDElVRRB2l2W3lZ+pjrmw1LfbZREKlx9yEj+gdpeOItJ6Rb64OfTC2LcPAOUQXnsUAMhcKcmAMMk5U4ZsqsR4lBtVm1gNAVkjS7Ky7LVe4hD44N7VGNKCy+1DP9Rqmm/quiwYrh+WzcjbqwdYs+WsiA0UPvnJGw97otRl7DqjGDeFd+SkpFtr5brE15rko4G2rSGiOOLaeY+asi79EXCHfRTiI2jNG3Ju8oZsK2/PRQvpHKdj/vhfYNb0m+qPJ1mkKE23lPZ6zXbXAH9g1okX5mGyAtHph0m1LomFNYVeBpwfg5HzDOeuWqLgx0PrbyPXb8UQYv2hXdbzV4mmLrSEL 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)(346002)(136003)(396003)(366004)(39830400003)(376002)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(6506007)(6512007)(52116002)(66946007)(66556008)(316002)(4326008)(8676002)(8936002)(66476007)(6486002)(478600001)(83380400001)(1076003)(2616005)(38100700002)(6666004)(5660300002)(7416002)(2906002)(86362001)(41300700001)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6u4g1OP5QkpLJE95y/hVsrKoKhkysPtKhvwNVuEpRrdqRNUNQlRcuqhZpXBwBR5NEXcNNhoGxkPRWWhSRFicyHdOD0lkEjlWZmDt+NwqrrZRYnrUMYwHeXZGb+ErSVEP+WuRjVIDGj0T1M6zLlj1SVo3FWnTcB79DrdeA3HZRxF5hewnmr4/Fc/IJ1YxSiQ0egsP3nFbDhHeCe1y5zQSVvd/S9mtNC6BFALWG56L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H+5juFU5KkHuRVWx4b1MCIunHeA29e0EJ7RkXbGK5gsTunqprtKypxqgs1SDMocDgYUZuSASlpaSjIGXqfNNNgXBIaOO5vV+bgog7Abno5BtsUzrCfXIFAhwG6JT0yJZrh9OWIT8ggeDXHH6Boulag/GbCWmsQzbaCDksioPEPC+JzJU1PtfWKARC3i12PfWGEdqjVaSU8JO2FsBwnqTzLhTF7Y9RgqqSM6MOTDunsN9r+qZkPT1VRujyj/7UqrSrUVNzDBpcSsaDfdZjeJh1Gug/XK4LGGLVKK6qkjh8oZ3CRQvNw5YVL04QSWCR7uV5esrS8NzAVq8idVNlPZoN2igjLycTO X-OriginatorOrg: kunbus.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d05352f-e67c-461b-edc4-08dbe8f2ddd9 X-MS-Exchange-CrossTenant-AuthSource: VI1P193MB0413.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2023 11:30:00.5987 (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: 2W4ArfopuC7TAJg8TDADqmZQijow9Vk2TtAs+V+2Sa/raR0MfRltEa70yjmlsmuGyyWVtZ008/Nupwz4tz9A3Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8P193MB1060 X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MIME_BASE64_TEXT, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 19 Nov 2023 03:32:53 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782991893617880652 X-GMAIL-MSGID: 1782991893617880652 |
Series |
Fixes and improvements for RS485 (RESEND)
|
|
Commit Message
Lino Sanfilippo
Nov. 19, 2023, 11:28 a.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")
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 af175c803c22..b96fc2ba8596 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);