From patchwork Wed Oct 11 18:15:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 151518 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp728997vqb; Wed, 11 Oct 2023 11:17:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvnOo1sbCMyz0CZEsegRvpj/jh8jGANeXsJeuvvB5FB+XQfoyVbPxL1BynBKWIXp/5p8Ro X-Received: by 2002:a17:902:e885:b0:1c0:bf60:ba82 with SMTP id w5-20020a170902e88500b001c0bf60ba82mr24946411plg.5.1697048245813; Wed, 11 Oct 2023 11:17:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697048245; cv=pass; d=google.com; s=arc-20160816; b=yOyB3AMgzdpQiujFlfwzhI4CE7bnzhQb+lD+DU2hk7vf0XXQJ9obJjSrgltet0UKRK 7121ZtxmTD+5uI+D+ws4GfEd7qPNUNWnyLuHku7bxEicO+FvJZKbkE8pIj1qkTb2G5Yc phB0Ndf7eVU6ohiD+/RrChmoqP0TMuWM648bxTy9gaWHezUeO5NQQ1Da47Pq5H+Q3TRG cl1Mk8G/7tfjnmqDq/Tel3U2x8ed0LUOsl3+dZcD83LDMoepcn0/tiwEEw46YTDvVv1V EP/ZLSyalvZkDNxC5UY5gccwywhXkeL2XNgBu4PdEaOJTw6W3zSjTP6iYprp4+23Bkmk Px7g== 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=oK48PGvsIKhBF+d21ldU+Id6JckShcS/hsDClCbGVHo=; fh=USa8qwlB/WGEeDqy6MOlMhU1i9vBvqThUFWUX/qv1Ho=; b=bu70TljaXG6OK1c2MAf+iKmlx7/ebSO01PsezjCtXvCPgXP7SFFL4/r9ygaKdaY4c7 9wiVjmpIXg7I5j1v2vZ7SvGClGbe2IPORLCMAk26/0hadRg1XEYbUyzSmBl5AdP/OWgC Asor81Of7H6W4QOAH52bkQzK/58dLuh9lHxzAgmuBIxNWP4OCtr2LvrUhjOMe7opQvP9 DWAR7PiYgIlMPcuunDBvysaKnFGfZITtGTxzr2iQ+fxTBk59hGIqK9t3ijTfWHtUrFV5 jxfx6FHbSA4Sz7E/si77QYdHMsxNymgDqHFII2UIJUNc0WQnAQ/OIk2GjuxGwBIofO7J btOw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kunbus.com header.s=selector1 header.b=X799JHKF; 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:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id h4-20020a170902680400b001c35864fdbbsi219498plk.406.2023.10.11.11.17.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 11:17:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@kunbus.com header.s=selector1 header.b=X799JHKF; 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:4 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 howler.vger.email (Postfix) with ESMTP id 02FC1811245D; Wed, 11 Oct 2023 11:17:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346995AbjJKSQk (ORCPT + 18 others); Wed, 11 Oct 2023 14:16:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232891AbjJKSQU (ORCPT ); Wed, 11 Oct 2023 14:16:20 -0400 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2041.outbound.protection.outlook.com [40.107.6.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85893B6; Wed, 11 Oct 2023 11:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R+hdFfT+R15uih21pofpL3/QwClNrlJeAskkXX0B1hgKPuAZ2Zpp/V8JbZqcx9SKHYUDfAF36dn7d/4A0Ch84YOk59NmfZIVGtRzbMYS1BcAFEHfTEfCziqO9Wir3BlBkKhR6gCjFUV+LnF/hVhFUUZKg7x8t1IvvIVCYu1tSx+BUv8Kd6ymYXYaRuJAggrNi2h8V/8gCPqTxK9cVED07J/l2LxNlFMqcgSDHq9nENaIQE3vqkblPZaeG68m4XkHpwp8thMo2VgrI22XrdSxoYLSoibyCtsj7+yPvmZ+P7XocGVSoNDHrtZbKfgzJ3sPeUs7TOyqFVipQVlw3JOhnQ== 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=iRGED2Fi0ar57sU88uftMc5JL3RqAmFd1gT53JxXLCuIHKzqLi/2oQdV5eDNbBiUzmO9GKESqMHdiCs4gXWpEciFwaG6FVinc71nZt18HP0BYCatAn2HVuWstQdl7aR2i7i/S9639jumM7kGAufCkdDEwPNDboJsvH6x0ohFas+LMLx7uB1OHbQwP5XBA5q0Cc8lFaQCMKsoyucL5h3q473oGPoT0GowQ/iajEnPeqbFQXRGOvKFOK9zwwlI3qEbCZTdyhNgeHs0jfXlX9NpF6GF4w0m9IZ3JQ5Ouo9kEHT/8pl8QVgkraVIxH9wiu5SpaJ4GNZkwFMZAjKvDEfXZQ== 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=X799JHKFKYF/N1d/OuJ86tBRjc88huH/RLbaPRPCAVfCFSA6UyroiWbStH3YqmmSSUuzXqer9vgi0Mnk0D5yAUKqduD2Y4eks8FK9q5IHCWznPDeltQSp5rA3o6UK6hJuawK5BCzjkcFVso95isDP7XGqtVWNWYWWEfJcViV+Bw= 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 DB9P193MB1497.EURP193.PROD.OUTLOOK.COM (2603:10a6:10:26f::16) 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 18:16:11 +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 18:16:11 +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 v3 3/6] serial: core: fix sanitizing check for RTS settings Date: Wed, 11 Oct 2023 20:15:41 +0200 Message-Id: <20231011181544.7893-4-l.sanfilippo@kunbus.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231011181544.7893-1-l.sanfilippo@kunbus.com> References: <20231011181544.7893-1-l.sanfilippo@kunbus.com> X-ClientProxiedBy: FR3P281CA0163.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a2::9) To VI1P193MB0413.EURP193.PROD.OUTLOOK.COM (2603:10a6:803:4e::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1P193MB0413:EE_|DB9P193MB1497:EE_ X-MS-Office365-Filtering-Correlation-Id: 43847260-053f-4bba-f5ff-08dbca86261c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pRYtO92ghuCmwL9JHuhswjOw1hrqbhDAy48W75Flad92NBkqdibTG8lkWApZgrBsqeiDJJuULCR60Vk1U7blWLiqqOuGkwD49KP1xL6ULFDfC2sFVlLtCi6C9JSaWgPxl2TF1fIwULj9ePnM53fVp2KyTJ5SkodaxoT1TbpuXpZ4VaFUPtCLouXHXq9oXpXmyokZ18VYD+alaIfDjdd8guf5wu7B3ImNuj3cTJuldOzvnQzjVOYpkG9JghnIkNuUSgW+9rq4Sqpqt9KfaqpmKVOnKHOpxTebaECRl7I2oHXtlJKlg3gFOXooFvHcnm7g6CZquKDn1tKAzCgghDhZAUfz6N9uyn20IBNfLkFwzE9CV2Je07pXHd4OqY0bheB1oHN2HPNG95kft+gHyMN5aaVGdvVY48YLp4G9Hzw/00WYlwPH/mSWoMyzfMb+kZRewpOxaibvYWo220/P6qeujxbV7imoMr7/U6wLTMRlhgHkDGLFdRlBSxg6zabOlPRJOqBrpavKj57hGJ+dYGM5t9AdNBfDDq2X8krv3FBfkEppdBNnsnJ4Kkiumdme2Cyl 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)(136003)(366004)(230922051799003)(1800799009)(451199024)(64100799003)(186009)(52116002)(6666004)(6506007)(478600001)(6486002)(6512007)(38100700002)(86362001)(36756003)(2906002)(5660300002)(7416002)(83380400001)(1076003)(2616005)(316002)(66946007)(8936002)(4326008)(8676002)(41300700001)(66556008)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DDKOJfUVJFY4/tBWkIyHhiiTogb17dvXGA4IgdBoNtnD8Ygh/9S9KpJaIOQBE/6dZxnYGfgTXHqXQU69c5cV6Q2X+IVrje/meaCqUJtPF6fPHIFVT2fNgEFvMdJfzldlna5irOqovOKeHSFWVDnMH/+SAhDgZLDE8a2q6QXoHnvD5Q0zC/11t1bLQfhxWw94LDT0zRkxDfTsUP/n4u5P1TvmiCThQp5Rj3bZ/fYgJgWnbM0Nt7+anbtTTo2Lpj2lvJPgPP8JzLmYHczDvi/1+mUY3YJKG4SuKTbdWjUprEkU+hr0a5olkSza2KLByv5bU3Rx5Lm39d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TKeytjNXINRrm1RuE8HCxju8FMyD9FkQ/U8FKK+uad2TtCPear9Vf4urod6fsseUvt/OKd8Bx/8fBZvKyqhCzCRvblJZGabLCtq67LAJDrijbuw0mg0Gqtb3jOgyc3Sy+K6MI734CcGD0GuadO0UBtO1R38rh4UZ53ZEE/DMXr56+LG2eRKGo3zRb0FXeFGmkNRU6hwVJJV6cWsK+1+ong63dKpULywE5glYfTqxs8yu/8qbCLGykdeBi0y2/Tg X-OriginatorOrg: kunbus.com X-MS-Exchange-CrossTenant-Network-Message-Id: 43847260-053f-4bba-f5ff-08dbca86261c X-MS-Exchange-CrossTenant-AuthSource: VI1P193MB0413.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 18:16:11.8130 (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: ovbd2qOxB/1Wb+x1VCnRcBiDuQMSeRVZWs/EwQCfLO8SSeQKuIkCWT8NYt98SaKfmVNz88mpgdFRVS2YTKKUFg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9P193MB1497 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MIME_BASE64_TEXT,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 11 Oct 2023 11:17:23 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779484061844741935 X-GMAIL-MSGID: 1779484061844741935 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);