Message ID | 20231011173829.10508-5-l.sanfilippo@kunbus.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp706404vqb; Wed, 11 Oct 2023 10:39:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGowgStfmeDdmhMZ58t2E7dg1+Ux3lXn6k6KEU1cj7wqjAvOAABnfWYJWf2yufmPSHYsQut X-Received: by 2002:a17:902:e5d2:b0:1c4:1cd3:8062 with SMTP id u18-20020a170902e5d200b001c41cd38062mr24683746plf.2.1697045970533; Wed, 11 Oct 2023 10:39:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697045970; cv=pass; d=google.com; s=arc-20160816; b=raNzLpOD95GxMK94kAOG5C+pMjCEApPRfJAcMDP9fTimbePkMdX+roJ35PjLpTVK7b ikm4XcLJcrYwCvme9MNY64604kdKi2B+V+b2NQYr7Vp31mmuqQ5KXpFj9KFatSppynm+ sd/yIru2lJXJltdcHmyvOiRzk6P/+n6k3ghNk9rERx6e5rjYXgryWY8veEINgkMlpeA6 WMeO1yfhT41zY1Laa5dEYv0D+CI1w4djUmDpXG53wDixqfrV23YdM2ypfsCNpC86u5m+ VXwgme8MESKx7D9BMYuKkUqwBLyBgRO23Gu6oGK32RlJR+gB48ENl9UmQAp6tJz+fa+9 lhaQ== 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=dQXVpqsqxfzkSBFXxGq+EjRaMRhPvtYJkZ6jR6nRxdLbga/xZ0zpQsZ2lyJA1smC65 G9YbhUMdaUx7yo04VsolGpXi9wKZ+nETBuqHlWr+DoSN2UlB6hIabidggociSB+7E9k3 9TXmdvhpkKHvdCXT3ZjoaOrZGabJtsdOG+W7pVZbp1coI+Q/BdLn9hRFuJ5zfZWKEUws QCrIQ+UPBEPki9q8EmyFPKj0dkoM2ipaG10OpIIHLbxv5lsQOTCItWoKMTU2E6o7PEr0 y5OTvCeVkfux5ZD27eCoJayDQ1ly3FdyNn1slFIOXtht40cmHoBnnN5cMsiB3k8hNE8W o9Ew== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kunbus.com header.s=selector1 header.b=0TSnZkBH; 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 a21-20020a1709027d9500b001bde9e8a29fsi184128plm.183.2023.10.11.10.39.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 10:39:30 -0700 (PDT) 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=0TSnZkBH; 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 B730380775B6; Wed, 11 Oct 2023 10:39:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230234AbjJKRj0 (ORCPT <rfc822;kartikey406@gmail.com> + 18 others); Wed, 11 Oct 2023 13:39:26 -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 <rfc822;linux-kernel@vger.kernel.org>); 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 <l.sanfilippo@kunbus.com> 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 <l.sanfilippo@kunbus.com>, 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> Content-Transfer-Encoding: base64 Content-Type: text/plain 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/4M8yM3yVISz2jIpkGK1O8QPz5UJUdXPD0JW6jc0vw4eVHV4Y2ti4LchO9pkCUG3XoCBGnUyxfk8PipLGc6BzeZven5C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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 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_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS, URIBL_BLOCKED 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]); Wed, 11 Oct 2023 10:39:29 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779481675694639462 X-GMAIL-MSGID: 1779481675694639462 |
Series |
Fixes and improvements for RS485
|
|
Commit Message
Lino Sanfilippo
Oct. 11, 2023, 5:38 p.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 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);