Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3877767rdb; Mon, 11 Dec 2023 02:41:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHtUVNkUBMvsJsmoXB2KRLvmL8LvuTG10EuCAIBUAuHGM5B5yRmYEJIHsE44LgFVvfaGf06 X-Received: by 2002:a05:6a00:2345:b0:6bd:4ab7:5f69 with SMTP id j5-20020a056a00234500b006bd4ab75f69mr4450969pfj.12.1702291297979; Mon, 11 Dec 2023 02:41:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702291297; cv=none; d=google.com; s=arc-20160816; b=uOyi99lXXZReSI9aZOmmgQqdai7F2eUCOTudkpIqFU/yqSqn4GJGzQJBtClrf2viET NoJVpF8TzGtPmuFZi5zvqn9NQ5u3eJ5SMWo/2KD3ItNDIMAJSP/5GblrAW2Db2W2Yut+ StRp9GVRqlMGiUlO9jfPCP39t0njMVYHFLXEJ5my1HTfd1DMc3PYJi46A3WauxwZrshT uuku3e8ebxs2dKDLid8/suvjsoYIjHq/mRm7u/blvO13Fw8b//kh8B3gGDZ3JrJT3CXU FGV/DakbDPc/iJ77fnlC/q/xz6uoMH5GP8XihEoU/DQ77xD3jg18B8ypMmvnN6ONMDLu wuyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=JE2o12TiAdjbnOrgE+t+sBVnDvhvBKG2dqAPzbd+G4k=; fh=mDo9AJ/yd0LvLDNxlF7M3XLvHnGX9YNrpHW+lPaHt54=; b=R+YIo/553dPlBKPz7f86ep/eCMQcU906pqUHjgCWE37/Rq080X7JxdSocQUkHxmgKm IYSSY4VLNsyJHDPrXuh7iRTttWREgtfCiW/NeibEdE3hvREtr8LAxxv5ec28GU63bauH TJcPtEG9S4mA+JPFXHGzaJxiKh6vDG7XXrlKBstvV9R7YTqo+5ZFI3Pnk89fnL+s6z+D eQe8xC/sjpr55gJYzeRVFHy8NRLJHWQlYXlMoV1hv2PYSd6wKaKs1oPIJhBVTjupS6Fd yAjL0S1qkRTS+Uc817x69xczbz9rnnd4o2GBXM8ZKnpyInWoPfoTe2B8DfNszI0RqfEB X4ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=c0RPyRIa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id e4-20020a63e004000000b005bd5a50b559si5693080pgh.715.2023.12.11.02.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 02:41:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=c0RPyRIa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 7837B807C748; Mon, 11 Dec 2023 02:41:35 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234549AbjLKKlN (ORCPT + 99 others); Mon, 11 Dec 2023 05:41:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234498AbjLKKlK (ORCPT ); Mon, 11 Dec 2023 05:41:10 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8B39A9; Mon, 11 Dec 2023 02:41:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702291276; x=1733827276; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=Ce2nDwoDwwwDy0UWSZtRXe6Ee4Cu3/Y2wE3oWfmwO4I=; b=c0RPyRIaiAiMLIdaFw31Anwas1Xk5kqBIAkG0E8ElF8AXDypipoG/qWv SdG1ZQzAJOPDWQ2/VnXTB8SOEWdnzEdJtEIq6G38JF/RGXsUFRiu5yhPx GbFucxZeTESuenp+EBtOid37nvqaFfUvWJO/H9O+VDhkcPjvrHV0CEPyW Mk44Xx/KfdlAzX8Axa+I/LlXLTbRr2rtZ2W0Zijohiyydm85YIeDIylGF KrboU1+k6qzlQwXXEDZvva+RqNG718+Srd98zsxxYkjoIIkNrFe/yQwQ7 0viLcU3YhvY3PxiJgnL2TioLKNT1aS3ySBjj1jzwSFkQUgYl4FCclkYKl A==; X-IronPort-AV: E=McAfee;i="6600,9927,10920"; a="425753432" X-IronPort-AV: E=Sophos;i="6.04,267,1695711600"; d="scan'208";a="425753432" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 02:40:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10920"; a="1104428709" X-IronPort-AV: E=Sophos;i="6.04,267,1695711600"; d="scan'208";a="1104428709" Received: from lmckeon-mobl.ger.corp.intel.com (HELO iboscu-mobl2.ger.corp.intel.com) ([10.252.48.111]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 02:40:55 -0800 Date: Mon, 11 Dec 2023 12:40:53 +0200 (EET) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: Lino Sanfilippo cc: Greg Kroah-Hartman , Jiri Slaby , 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, hugo@hugovil.com, LKML , linux-serial , LinoSanfilippo@gmx.de, Lukas Wunner , p.rosenberger@kunbus.com, stable@vger.kernel.org Subject: Re: [PATCH v5 3/7] serial: core: fix sanitizing check for RTS settings In-Reply-To: <20231209125836.16294-4-l.sanfilippo@kunbus.com> Message-ID: <6d3f6867-3090-a8ca-f72a-c645a358087@linux.intel.com> References: <20231209125836.16294-1-l.sanfilippo@kunbus.com> <20231209125836.16294-4-l.sanfilippo@kunbus.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-764256907-1702291259=:1867" X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 11 Dec 2023 02:41:35 -0800 (PST) This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-764256907-1702291259=:1867 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8BIT On Sat, 9 Dec 2023, Lino Sanfilippo wrote: > 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 c254e88c8452..4eae1406cb6c 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); > + } > + } Reviewed-by: Ilpo J?rvinen -- i. --8323329-764256907-1702291259=:1867--