From patchwork Wed Oct 11 17:38:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 732396 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 33185CDB475 for ; Wed, 11 Oct 2023 17:39:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232919AbjJKRjS (ORCPT ); Wed, 11 Oct 2023 13:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232848AbjJKRjR (ORCPT ); Wed, 11 Oct 2023 13:39:17 -0400 Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2088.outbound.protection.outlook.com [40.107.249.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7187E98; Wed, 11 Oct 2023 10:39:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iRuXSixgPJs38mZPzNP6C3nsOavSxOGX7lo1/WGijZnlDlRQ8eWrxxxf1W5s4wgsX+daCazjDoNk0OfHsJzU5zHmwJv59nuV1Irt3sqSpAzTt6XOUI14gX4vxqqKFz0DRVxQ92W8xdnKI+3wReLTqeXzcrJsbAb2MurBHUq5v+GDT8d1ObwPgT78MRufFnn6e+VTWTaeFZyRR4iMXaR4MdoTSt8NaHGrnXKN8droefuyWzWrPa/X2EBSK5n/f0/KGUgXgk9Nemg4WkpziIbimHzdJ74Si8SZwA2kNISu53wqk0WSoKQ3P2hnQNvLCIGB+4ujk7jcNRG4Q8g0PrDGtg== 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=oK48PGvsIKhBF+d21ldU+Id6JckShcS/hsDClCbGVHo=; b=OT74+xrYWxE5LGaSillEvi+mLxhaZtkyCcWGYjfWMFCUdR7f/FkIFke2SpWEjp7IAOUU9CIGUzWk3s4FH1GtZcdPTv7dpepdlNYRA6IJh+cOju2UhDv3EHe1iCQMQQDWvaTtDWlGcXXb8dNVqDdI2JsrV+M0FQSgvNcWVabDo+J27fa4vZ4dV1S4OGG9880eh/18gZ/tKu38kkGM/ubCpWY/cV9tdRAs03pg1mtdIDl4InnSu0PH2Sqhuf6EkjZFnnEHctOai0ffUDm0I63BzltP9DW3uDDQKRp8/fv7C99WAUSPV4F5oW/COXndoYngLuuOqEyQS1rrU08ENJ0UJg== 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=oK48PGvsIKhBF+d21ldU+Id6JckShcS/hsDClCbGVHo=; b=0TSnZkBH9ERhP96Zj9iw3FCyjuI4u8zhWICab8u/G7kBmSaPMRW2f97ngrPpPgUoszJPWWS9F+ZTJeUSwfNCOWV7acV4WScw6KsVT9UfeVl7DTyeGNycu6Vsl2R6KnL6XS+MA1zdDe6AiJHi4849dzzkpBITpQIVWRHhyiiPg5Y= 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 AM8P193MB1187.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:362::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.41; Wed, 11 Oct 2023 17:39:06 +0000 Received: from VI1P193MB0413.EURP193.PROD.OUTLOOK.COM ([fe80::550d:2425:c0ed:3e59]) by VI1P193MB0413.EURP193.PROD.OUTLOOK.COM ([fe80::550d:2425:c0ed:3e59%3]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 17:39:06 +0000 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com Cc: 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: [PATCH v2 4/7] serial: core: fix sanitizing check for RTS settings Date: Wed, 11 Oct 2023 19:38:26 +0200 Message-Id: <20231011173829.10508-5-l.sanfilippo@kunbus.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231011173829.10508-1-l.sanfilippo@kunbus.com> References: <20231011173829.10508-1-l.sanfilippo@kunbus.com> X-ClientProxiedBy: FR2P281CA0093.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9b::18) To VI1P193MB0413.EURP193.PROD.OUTLOOK.COM (2603:10a6:803:4e::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1P193MB0413:EE_|AM8P193MB1187:EE_ X-MS-Office365-Filtering-Correlation-Id: e6788358-77d6-4af2-aa7e-08dbca80f7f4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nbRLNG4Hp5hrGIXlig/UQx2qtT2mYfMPwchd1VWf1a1z5+eAsHTwnk4Iy1CUE90jo9TV4un2CXIEUJrix47SHMoHplkwxEJr1ruL5aCJSdlhvEFnR+DckRMDleUYxs/WeU4k+8CvUXWvnGXB6ZLDA/Ctod54VDqg3CiJR8BrS91vFFK6hOBm/rlCuozxLl+Az6IRMb18RZ7HtM8NNx30G9DSAe5rmqioNG4mfoD/QcGVKA8xt+GjolbnjPBeZhjFOFq5a0BjqNUEGbO2ksCyD/gBrmZeOfDTGAmYCgT7pqg8fSyqcPekLnQ4dUR5XPNe5EAeiT+cSFGlvfFz9wjXkWXfXfJ4Rm6UPHQh9+9UD09zirbFGAhjMmGAvfHtZfidfkeUZQ1Uihi91DHW6ZSPp9Ij8GFU8u/V+rNwWUF6R2CYLaMBTZ9BA9XURhjZOhBPqmePSQ0h4xhzVWbElJt/04w7yxijKbUPvbwuRI7Vxpio1EIJ7vJE101yfLaj15ii0Pf5qBMHTUhSpiPMl/qpVWjhIjSQiof6i7rRpmXGFAgwKfz66eyStLKq55hjz8ob 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)(136003)(39840400004)(376002)(366004)(346002)(396003)(230922051799003)(186009)(64100799003)(451199024)(1800799009)(6666004)(2616005)(83380400001)(6486002)(478600001)(1076003)(52116002)(38100700002)(6506007)(6512007)(66476007)(66946007)(66556008)(4326008)(8676002)(8936002)(41300700001)(316002)(86362001)(7416002)(2906002)(36756003)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: heBXJxpCyGJj/bqZnix+xga6zMxVHMayjk9sHXCAlKiBqySPMbeQCqJohOCe3AJ1j9Dcfa4ZXsBrbkwO/7AbGWmPMsmKXlAirgdm3PmrZsXnNdjTn11eUMZfEI9zu7IgpKoqrq4wrHN4Dah4rjuu3V7K6DAFP/4M8yM3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RuiuUBeN3oD4VWsY24ti+zI6YYaWlKjNyoLQFanxxA9FLwnsxyGLbEu3ZX6CfOKfo/l/7ZS0nGjDpSdR/DqCFTZB4JhKjuAYqWoGXyB5h7j29zClBuEdXDQHg8mWw875Ue71G5QDriEoN+P7kVcEaLCoL3tPQ9V7M6lsLn0a1NtU6ur43GIEQ4voOgTFTy3uMNPZmvfijBKrlxoGXASAe6q0bKUdjEQv8ifWqp9J9D9Mjg4TpOsLTUIkt1s2ScBWC4W6T5ZGROehPIq0XQNYKoFh+Jc59TGzyT+2Vaw+lStHXLUzIpoQ09S3c/MPUn9G1owUuyxgPq2ZUUfW+PSxVj5u6Xsd/WK/NTYtKfSniodYtSd/G5kBs7dI1Qwocmi7aUdCyOTvIZfn57J4yXVZoxKIDjtBogvjDBIs X-OriginatorOrg: kunbus.com X-MS-Exchange-CrossTenant-Network-Message-Id: e6788358-77d6-4af2-aa7e-08dbca80f7f4 X-MS-Exchange-CrossTenant-AuthSource: VI1P193MB0413.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 17:39:06.8742 (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: nwcIsKvEWDJB60NZDevImlIlIArjzwRAk2TI0VUJm+jC7T4F9YtwmyERbmVAlrBwdx/VfE2IHzrPSCtJZvYaZw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8P193MB1187 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 697c36dc7ec8..f4feebf8200f 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1370,19 +1370,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);