From patchwork Sun Nov 19 11:28:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 745338 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 07E69C5ACB3 for ; Sun, 19 Nov 2023 11:32:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232059AbjKSLcw (ORCPT ); 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 ); 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 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 , 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> 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+WuRjVIDGj0T1M6z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z4ZVWdKT6cn4Y6zlgibvp65OQKMIoiYCblofozNUxwAAOpbpoEsG+VhqvPGsyR39iB2klZCaqLaqqxdpCESp+nYckj9J9H+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 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org 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 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);