Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1508944rdg; Sat, 14 Oct 2023 05:23:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMq/6PFW8pWcpV3kdKizhLCoDGAPAkMTQcohQm3WD34SV80jz/9qqL9A8KR8cvKOnPleKN X-Received: by 2002:a17:902:cec7:b0:1ca:4092:7200 with SMTP id d7-20020a170902cec700b001ca40927200mr472950plg.54.1697286237926; Sat, 14 Oct 2023 05:23:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697286237; cv=none; d=google.com; s=arc-20160816; b=yxtLgDi1wyLDbOYjM+09JYzQ0Ixf8Me3uEy5K2AXl2kOWBNaI0UXhYqLdxhFvxMMc0 zl+DiUeDW7gULy5eihr0xq/m94AjThiIroCJCP+QWEPVTIUz2KHdQqlh9vlm4xJ/m6Dd eRsrHoD6bafYH31LRuriVud94/N+HyuIj3OL6QloObY1VsZFAw0hfEbYDRBJnUsauNfi J8woI1T9xPp63+YLyWm0RzJ/WyG+v++qfdbzcS32FuUL09LlFL4FDLAc5dzjwOh3ngEQ dguiygFcXqNa+VnqSRFkFo7HKlSaW76b57a4X2uKz7upw+TGn8xEQ+zt9Dy6AszI5GDO m7CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=rcfISLoUNHOZHH/PO7INvR8X/sUWs0z+28+R8YT2SiY=; fh=TDSg65lQnbfLczwCctSFgsf/V3PapyJWy6AOaZMyBiE=; b=kvc/2wrzq70AzKWV6Q84apSgpbPF2QQbKrIiAoxXoys8qwmS0Qj7VAHYmLdTJTJk/M Cb4IYrhqYy4ojFxu1EltDKLR4P4Z2hBcaAFgjMzWl69nrA0TKM7WRT8q2vePndMDd5wb 1SpeHS4U3aFFmSpXJNpg9aUlfY0+E7LQ1q99Skn99uqD4C8Cdm/8NM8VrIskLCRjAiCt SYkAjgYmaWNUSFxF4mIlykvCnEOpTTmzVa22E+jKQH8RA8jmWllanEea6SPT75FwWLp4 FUUiJnS1NIPgSJ+8kew3/6DJs17AX24o25c3n5odMU8o4D5K+GjA0THTJeS5aUqBtC8D l+GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=baYtoi4D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id e5-20020a170902b78500b001ca485b8514si237695pls.646.2023.10.14.05.23.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Oct 2023 05:23:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=baYtoi4D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 4C5168030791; Sat, 14 Oct 2023 05:23:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233193AbjJNMXo (ORCPT + 99 others); Sat, 14 Oct 2023 08:23:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232957AbjJNMXn (ORCPT ); Sat, 14 Oct 2023 08:23:43 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 385E6A2; Sat, 14 Oct 2023 05:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1697286197; x=1697890997; i=linosanfilippo@gmx.de; bh=kgDuOk3z1Ea4qWhQuI9kBo9177OQ8y0oXsIYIljyoes=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=baYtoi4D36rhBH1R75lao0TrIMwT7MSTlReTcTd2/u6L8ytG2F+iablgvpbkCkb2tr4ZMG3i4Ae zoRFLLXRReS87RU4+d+oOyfyfmBqXNzIjc6ZBkMY5up3TdND2RB1nI0HD4NiVRKzm50Imt8Y+6V5O t7/sBEG99IW/vUDYmDGRn7itTTCgjpm9j3PUID1vNyE9u/bc+4t7pKePjj4cF6IG9uiN7uKdu69ci Xoz6E/t/DRGuwNc6rREYMumcKbZN2JzoqStUQ2Io97u7WrX9Qr/NOE4yMug9iL50DbT7ip28y0emn Uv35oY/mHqsjdc1rLYQiWHZDrYHPcgn6m0Ew== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.2.42] ([84.162.21.41]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MNt0C-1rBW0K3zlQ-00OFiE; Sat, 14 Oct 2023 14:23:17 +0200 Message-ID: Date: Sat, 14 Oct 2023 14:23:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 3/6] serial: core: fix sanitizing check for RTS settings Content-Language: en-US To: =?UTF-8?Q?Ilpo_J=C3=A4rvinen?= , Lino Sanfilippo Cc: Greg Kroah-Hartman , Jiri Slaby , shawnguo@kernel.org, s.hauer@pengutronix.de, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, cniedermaier@dh-electronics.com, LKML , linux-serial , Lukas Wunner , p.rosenberger@kunbus.com, stable@vger.kernel.org References: <20231011181544.7893-1-l.sanfilippo@kunbus.com> <20231011181544.7893-4-l.sanfilippo@kunbus.com> <40e4c6b1-e217-2926-a351-bf685a5b775f@linux.intel.com> <63b62f6c-d97d-8d45-1612-968ef74b6365@linux.intel.com> From: Lino Sanfilippo In-Reply-To: <63b62f6c-d97d-8d45-1612-968ef74b6365@linux.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:CHN2pNHaAkw0ZESaLnuGgSm6m6EKCzvkaP3fYPHWXDJPm8blbaR 1SvWzi/huJIP50I3EY9CvPuSJF5a/GqlaIgxjbqZENub4y/aumnjrINqe0hIuWCyVXJY7oZ yOY1HGek1NFehYlgQGEwF2lwzPtjeTaDp7m7tQNyO09UvstSh7VuHqR3jh6GqDbH2ck3QB2 zzuOqMfk8QVZxIY59kaFw== UI-OutboundReport: notjunk:1;M01:P0:smEzDPWVI2Y=;uVqFcyRNYsaSTA4KRKzG75nbiRu nd1nafhYNxCBNLPACMbRf+9R/FLLTAZQ5F4MoZdZd1HRhhqRj7Vt273DeMpVMI9ki3nOrTYMG MrxUpjxN18lZXMG6sVvn80fPyaGlXNnYQbSEcUG++tPCK/apPzRYdHGuI7UB5Q4VstgMwFDUJ VAnt/LjiGbclPxP2LBKPH646RpovSaoQf6iOq9eWDrVTRlT529qA9NwfrrMZxhxB39r4WcI5E Bzoni88qhfA19p60Eg/XGbHoxRZ00yp0oILbUI7umFVQ9tuyhOaPEcc7paQN4j/bo0T//pdhO mGCT2gYkT6cJvY0ZCUyX97fH9zO8O8e4P9t4CxhMNzi3QZPw8fzZwiBhZhME/i0Ld2/r/lHCK T2bhAJ7cqzTyY2Gau3x+9znO1Pw9nlBMCCuR9bbJRv48PzAzm51k+z2WjbYd+HuThyc1G6u9s 9ekFjOdoDvBwVj9c5G4HUb9u2SWxz6mImws3r0gBiQnXJkKYF+6c+1pQmHzKXtmFBa4mQ7pCi LKASlxHgHvOW0c/I3jaqRZQcsbCP41/psTBENAOYD3wLZbRf3bY4v2biXjhqfxu7i3w6Yr8Ls 9DffQeuauvy2rYhqQ4yhxa/BI2NY1WBSJhIdYbKy5sp4Y250dLcHj//Q1q7fGotTk5STOTVGM HxUM5fzncxHDtjSPZ3MGkOSjBySFS7wrqlW+5XjqfojOFWBlQA0E6LAicC5DjQ4naqPd9SnoF fguYsJmCAapR19oz7Hay1PanBq7US/gr55zeYkBtbgaErRpKaogSWUBOj+0nQdD8Ck93+xIEN PGQzuSWiUeRVfceo7e4V2s1kMeDC+G8m+y/ewJ8LivnpTayJcu6WZuxI03+oXik07ld7KeSSo BvQPY8E2ztyv7N2pUdeMrsfM+co9C74UYeGsJq5cpD/3YtM3JRaUNhVB2ao3stoGbiadWRXK/ C4upYg== X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Sat, 14 Oct 2023 05:23:55 -0700 (PDT) Hi Ilpo, On 13.10.23 12:24, Ilpo J=C3=A4rvinen wrote: > On Thu, 12 Oct 2023, Lino Sanfilippo wrote: >> On 12.10.23 15:10, Ilpo J=C3=A4rvinen wrote: >>> On Wed, 11 Oct 2023, Lino Sanfilippo wrote: >>> >>>> Among other things uart_sanitize_serial_rs485() tests the sanity of t= he 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 configura= tion >>>> is adjusted and RTS-after-send is disabled and RTS-on-send enabled. >>>> >>>> This however makes only sense if both RTS modes are actually supporte= d by >>>> the driver. >>>> >>>> With commit be2e2cb1d281 ("serial: Sanitize rs485_struct") the code d= oes >>>> take the driver support into account but only checks if one of both R= TS >>>> 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 unsupport= ed >>>> 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/se= rial_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 &=3D supported_flags; >>>> + >>>> /* Pick sane settings if the user hasn't */ >>>> - if ((supported_flags & (SER_RS485_RTS_ON_SEND|SER_RS485_RTS_AFT= ER_SEND)) && >>>> - !(rs485->flags & SER_RS485_RTS_ON_SEND) =3D=3D >>>> + if (!(rs485->flags & SER_RS485_RTS_ON_SEND) =3D=3D >>>> !(rs485->flags & SER_RS485_RTS_AFTER_SEND)) { >>>> - dev_warn_ratelimited(port->dev, >>>> - "%s (%d): invalid RTS setting, using RTS_ON_SEN= D instead\n", >>>> - port->name, port->line); >>>> - rs485->flags |=3D SER_RS485_RTS_ON_SEND; >>>> - rs485->flags &=3D ~SER_RS485_RTS_AFTER_SEND; >>>> - supported_flags |=3D SER_RS485_RTS_ON_SEND|SER_RS485_RT= S_AFTER_SEND; >>>> - } >>>> + if (supported_flags & SER_RS485_RTS_ON_SEND) { >>>> + rs485->flags |=3D SER_RS485_RTS_ON_SEND; >>>> + rs485->flags &=3D ~SER_RS485_RTS_AFTER_SEND; >>>> >>>> - rs485->flags &=3D supported_flags; >>>> + dev_warn_ratelimited(port->dev, >>>> + "%s (%d): invalid RTS setting, using RT= S_ON_SEND instead\n", >>>> + port->name, port->line); >>>> + } else { >>>> + rs485->flags |=3D SER_RS485_RTS_AFTER_SEND; >>>> + rs485->flags &=3D ~SER_RS485_RTS_ON_SEND; >>> >>> So if neither of the flags is supported, what will happen? You might w= ant >>> add if after that else? >>> >> >> I would consider this a bug in the driver, as at least one of both mode= s >> has to be supported. If the driver does not have at least one of both f= lags >> set in rs485_supported.flags we could print a warning though. Would you= prefer that? > > 8250_exar.c needs to fixed then? I was taking these as things one can > "configure" even if when there's support only for a one of them there's > not that much to configure. As there was neither in 8250_exar's code, I > didn't add either flag. > But I suppose your interpretation of those flag makes more sense. > IMHO this is consistent with what we have in uart_get_rs485_mode(). This f= unction ensures that we have at least one RTS mode set (with default to RTS_ON_SEN= D). So concerning 8250_exar.c, I think it should be fixed (havent noticed the mis= sing RTS mode though until you mentioned it). Would you like to provide a fix f= or this or shall I include one into the next version of this series? BR, Lino