From patchwork Wed Oct 18 17:48:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 735436 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 C1102CDB486 for ; Wed, 18 Oct 2023 17:49:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231378AbjJRRt4 (ORCPT ); Wed, 18 Oct 2023 13:49:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231375AbjJRRtr (ORCPT ); Wed, 18 Oct 2023 13:49:47 -0400 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2057.outbound.protection.outlook.com [40.107.6.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FEC9113; Wed, 18 Oct 2023 10:49:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nnMTf1S5RputoZxYOaUfCTKAc1Z7DRnT1hHLFzsYNOvdnHzMYVDFEDnbFHWp+TQbTuPHz4QllDMxF/GleRwOatqNR15lxm9ELvRnSeVqb7wDqGOiIDfoyaCGPpmIcH8AixE6wwMKBnKzpi2lbpJ3RVCEoNtxGjjb55N1+CR1ZHmVgOLi409b4xPeAWPH6XLhq6D6Sp+Gjljxz6waMrZ2VSW4pY1hZwsicgZmTn+gpqeTYT9VNc/lC498SifSjV8X30wZFiBNesCmuRmALhgu+k26RNn2vUBa7s3rMdwDJQUSugrfjh47ST15PEwZC3GOIbAOgTSMzt0VYpzvJvG1wg== 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=em2W+/JhkP+uQxksZVkmIQVWa1dzHka/9yRLKurOJYg=; b=SCLUEMedgh8ITcQs6+f94GWm9JeMHShj6yVYkN/hr6QEbCZuxbPkUccXZsI8bj7jb1Gm4JM8PTzbpyXBGXpWKNj0CK4cko8JuHB04+x7p+yDAmRW+8QCYfMcEoi1S4uJ55t40dg+sLlWJ7RZmDGjd62Uq22KYV69S3FiypW28K31+g+xQB2iB9GCwn9pkYgHvhPb9ib8AqDDRoMm033NTRWCiDT5gcarhbTxNM5Ewi/rn7A2Q9GbjQkACozXjTUNR9GNyTrvjxGlW4S4ZlDK4jss4aeQdyqbg8yS7jwoAUUbpIckOW0jQKzrw8T5ROiiwkK4q2B+HGjcBtGpe5Bg2w== 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=em2W+/JhkP+uQxksZVkmIQVWa1dzHka/9yRLKurOJYg=; b=w5hpAhrx/6l4oB8VdG+yWji52E3ShHriK3PFMwgWSytjzObqte2GokW/Gi41Yj3YVJ2p23ytHn0Oj6EpQYayBijG8fzj2jR3n5lJsQMhuwW9frP1KaNcAKOL26hoiq09urzVfg6TKFqKS6w2NCBCVsQp7PKfNfN/xIcAtNQ1Sz4= 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 AS8P193MB1478.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:350::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.23; Wed, 18 Oct 2023 17:49:38 +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.6886.034; Wed, 18 Oct 2023 17:49:38 +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: [PATCH v4 3/7] serial: core: fix sanitizing check for RTS settings Date: Wed, 18 Oct 2023 19:48:36 +0200 Message-Id: <20231018174840.28977-4-l.sanfilippo@kunbus.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231018174840.28977-1-l.sanfilippo@kunbus.com> References: <20231018174840.28977-1-l.sanfilippo@kunbus.com> X-ClientProxiedBy: FR0P281CA0130.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:97::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_|AS8P193MB1478:EE_ X-MS-Office365-Filtering-Correlation-Id: 542f69b7-d790-44c7-52b6-08dbd0029966 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OcaPmEYr4KqEbqe7Ba39nGmo5vOvDG5M74RJvTz/fktGDr4UD5BVhh0NwQ+98RIZilVflxKc6yiQZULi8Og37W9Eqq81ez/rTI0ygMEudNHIVDjhIKX2emmAEg5c1g7DpVBp4XWsRbp6XnQg0dGQ7FE+XtQ/7gcIl3P/brYt6fFRYzbRK4rrVuPdA1svatAxzIIMWM8Ogwaf0PMa6YmMmxywTgPENcdrSG49Tnpj4Am2usebTsWSWm0oCIDKQMShoPQYNzZtH+N5zojnIpremax1er/1qU5CKFxexC/uf8qNAYg/zLB6zuN5ART0VPtCpvBt7qBglOYEoGdSQyu8CC3zTum+NffeBdmfmOGNY/8YgKehpGLQNG76OWV0I+b2dII4ZdbyLpIrVgkyFkBtx9GG/xmbsJejspBxB0wxgfReCenthihkrOrb6i5yb1VA2SYeDift/tn3uqWhEqhwrh6BG5oqqQoJwLw4e18+QB6WNyv+Q6yLuUR94LSBEIp/ksRgwJeU5zmvoqpPaaB1vwTn6DZW4kw/l65DmXAnH8AtWEfpW89zbXlGV+a9sVzg 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)(396003)(39840400004)(376002)(346002)(366004)(136003)(230922051799003)(186009)(1800799009)(64100799003)(451199024)(36756003)(66946007)(66556008)(66476007)(86362001)(38100700002)(1076003)(2616005)(83380400001)(6512007)(52116002)(6506007)(7416002)(6486002)(316002)(478600001)(5660300002)(4326008)(8676002)(41300700001)(2906002)(8936002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hNwKmCMBvMDoCVUkoOiyfCg7dL8tW6RYJmJl1FWLZuBhwfiQqHJq8rhUvwM9MfoF/eTW/tzsufplUmZ8JXZaraceR34rCyzVfIbPNsSL+ESATyAcVSQJga/F15vaH8xvbDaKkBsKJmWGalKAnHTgSdJDfmjilplw1LZFaBj0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Le1gNXEBV66jxdY7d91Eu29iGi5vfzLg5lDJ31tqDCIgLEStFR46LgtE16RLhIzF+NaDoW/a0z2ns64Ma2FGP67P2ee2MhxcruINTf2M7xIYhvG1TyB8TnvMTxxlDRBKht4DHZNhfC04QWBS4V1AztTLcMtUXZkNv6XwDPniIUEeb3f3uUJPaEZq2WHqMVEQSLNiPYPFkGlS9cC6kgsbvhP5fJuav9f0OPbmKJsCL7MSFiVvLqiyxxv3T9idUL90+cCa3oPP10pOsP0vZguLOliv/Rqh+GjBL6wafJ/LvxvsT8LVPTU3uRCAwGwjM7pwdZH/3HJichLQxFUbL9jd7mEglo7uFN/YpsoiFD4kRJhP3p/0AlwfMXlx0PJxZsU7QISvXeYq25i03M01ONR X-OriginatorOrg: kunbus.com X-MS-Exchange-CrossTenant-Network-Message-Id: 542f69b7-d790-44c7-52b6-08dbd0029966 X-MS-Exchange-CrossTenant-AuthSource: VI1P193MB0413.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 17:49:38.6334 (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: OM7QtnvcXYajBfi0J0JlPE+XIdVcqjnlaPZYEilAG6tWrsUVv77dZ0h18gNgTm8Ug79O7xtc3T6RyfCNcFp+/w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8P193MB1478 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 ef9e9014bfab..f1d889f9fd6e 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);