Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1124879rdg; Wed, 11 Oct 2023 15:37:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXVow8BOUSM/CluCZsjNbDIsMQKldudQoHsrdQ0yKQVVJM9TXzmOopJOIuLXDUCpKlwp2b X-Received: by 2002:a05:6a00:1a89:b0:692:a727:1fde with SMTP id e9-20020a056a001a8900b00692a7271fdemr25240139pfv.14.1697063858503; Wed, 11 Oct 2023 15:37:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063858; cv=none; d=google.com; s=arc-20160816; b=f5vGnrw0RWE1MvH/Oo0Q9zSK9nI71euRQVWnOyb5Uk3iNO72cNPvHEOfjQPVsSRARp s8yVItYsDJBI6BMCiityqwOnNMUWt6xR2qgzQXIIYijKgrZLFNJ/CNl29CXXM08y03ET z5tk8MWbKuzVkqCecVlRicMpNlcaRTwn6cqXcZPPBER+CQdqcy+v9NOcsJ0fRiKjihlw kgrghXas8XG+wmSdnxqNkWPDt4vSuPFrtmoilAP69XufwfABEP7fKmDxGTrkuYPK0V++ JHgFCjK+O83X535IWDRzRWF2DVIqNiXyVhOJlcylHrxRVeJ2rr7gpVKCVacmj+40u4Nq n9ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:cc:to:from:date:dkim-signature; bh=AYz1EPrm1Fqih3X2Rnu7bOSa8uMT4hUtRWPajXMNV2A=; fh=z0scNXQXG3cZmo00XegdL2J4P38VlmGE7CVDpAkpwFg=; b=DbBS3b0v0VATuAMBwzjfv5SKzh51CmM5XGIP2J20nWzP7vfv3Rwk75x4my6CHPuBk1 x8AV/DLGZk0OQtVtZ1Vw8mehl8Yv8CgHqpXzSf5dS+93+tUkeIOmFeZsvsxhDiNtDfiP +fHhBmfXd7mxYdAhtsEy93hi3PWjzgRQVl6Jl5b4349fz/3+wP8XtI/Q1ogB/sszT1vS LYG4/TGTbyD2ZHJIcomz7IyJr+yJ3UHA7+S3aDgFulyXR5W2UOhKui92dKCIxX5Z90zV cp4gj6azbL6vnDE5mxcymxHlycs4DnXp1s+nJuIBop6oZp9IEEeK2Bl1JFwL0JTsMZP6 QqaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hugovil.com header.s=x header.b=W83zvwiu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id y9-20020a056a001c8900b00690d25b198dsi12890419pfw.103.2023.10.11.15.37.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:37:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@hugovil.com header.s=x header.b=W83zvwiu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id ECAA28026470; Wed, 11 Oct 2023 15:37:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230108AbjJKWhW (ORCPT + 99 others); Wed, 11 Oct 2023 18:37:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235192AbjJKWhU (ORCPT ); Wed, 11 Oct 2023 18:37:20 -0400 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2560C6; Wed, 11 Oct 2023 15:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:Mime-Version:Message-Id:Cc:To:From :Date:subject:date:message-id:reply-to; bh=AYz1EPrm1Fqih3X2Rnu7bOSa8uMT4hUtRWPajXMNV2A=; b=W83zvwiucyvyA08VAiLSuRRMWG kMcp8kjSKqz/q615DYRkbMrE3FAJCN8n1L1t/HyM1pn5dxjbZryzY7oe+aygqciPnYqmh9IYbEu5M KAMZDMkiG5WhVd0d5kOfC4665c0Ph9Dt40H7KYJSPu4trtquXfVlEe0Gp+yhkaTe3D0w=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:37416 helo=pettiford) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1qqhp3-0007ag-1r; Wed, 11 Oct 2023 18:36:57 -0400 Date: Wed, 11 Oct 2023 18:36:56 -0400 From: Hugo Villeneuve To: Lino Sanfilippo Cc: gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com, 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, stable@vger.kernel.org Message-Id: <20231011183656.5111ba32ec0c9d43171662a1@hugovil.com> In-Reply-To: <20231011181544.7893-2-l.sanfilippo@kunbus.com> References: <20231011181544.7893-1-l.sanfilippo@kunbus.com> <20231011181544.7893-2-l.sanfilippo@kunbus.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Subject: Re: [PATCH v3 1/6] serial: Do not hold the port lock when setting rx-during-tx GPIO X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) 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 (lipwig.vger.email [0.0.0.0]); Wed, 11 Oct 2023 15:37:36 -0700 (PDT) On Wed, 11 Oct 2023 20:15:39 +0200 Lino Sanfilippo wrote: > Both the imx and stm32 driver set the rx-during-tx GPIO in the > rs485_config() function by means of gpiod_set_value(). Since rs485_config() > is called with the port lock held, this can be an problem in case that > setting the GPIO line can sleep (e.g. if a GPIO expander is used which is > connected via SPI or I2C). > > Avoid this issue by setting the GPIO outside of the port lock in the serial > core and by using gpiod_set_value_cansleep() instead of gpiod_set_value(). Hi Lino, it seems to me that both drivers were already using gpiod_set_value_cansleep()? Maybe update your commit message if this is the case. > > Since now both the term and the rx-during-tx GPIO are set within the serial > core use a common function uart_set_rs485_gpios() to set both. > > With moving it into the serial core setting the rx-during-tx GPIO is now > automatically done for all drivers that support such a GPIO. > > Fixes: c54d48543689 ("serial: stm32: Add support for rs485 RX_DURING_TX output GPIO") > Fixes: ca530cfa968c ("serial: imx: Add support for RS485 RX_DURING_TX output GPIO") > Cc: stable@vger.kernel.org > Signed-off-by: Lino Sanfilippo > --- > drivers/tty/serial/imx.c | 4 ---- > drivers/tty/serial/serial_core.c | 10 ++++++---- > drivers/tty/serial/stm32-usart.c | 5 +---- > 3 files changed, 7 insertions(+), 12 deletions(-) > > diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c > index 13cb78340709..edb2ec6a5567 100644 > --- a/drivers/tty/serial/imx.c > +++ b/drivers/tty/serial/imx.c > @@ -1947,10 +1947,6 @@ static int imx_uart_rs485_config(struct uart_port *port, struct ktermios *termio > rs485conf->flags & SER_RS485_RX_DURING_TX) > imx_uart_start_rx(port); > > - if (port->rs485_rx_during_tx_gpio) > - gpiod_set_value_cansleep(port->rs485_rx_during_tx_gpio, > - !!(rs485conf->flags & SER_RS485_RX_DURING_TX)); > - > return 0; > } > > diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c > index 7bdc21d5e13b..ef0500be3553 100644 > --- a/drivers/tty/serial/serial_core.c > +++ b/drivers/tty/serial/serial_core.c > @@ -1391,14 +1391,16 @@ static void uart_sanitize_serial_rs485(struct uart_port *port, struct serial_rs4 > memset(rs485->padding1, 0, sizeof(rs485->padding1)); > } > > -static void uart_set_rs485_termination(struct uart_port *port, > - const struct serial_rs485 *rs485) > +static void uart_set_rs485_gpios(struct uart_port *port, > + const struct serial_rs485 *rs485) > { > if (!(rs485->flags & SER_RS485_ENABLED)) > return; > > gpiod_set_value_cansleep(port->rs485_term_gpio, > !!(rs485->flags & SER_RS485_TERMINATE_BUS)); > + gpiod_set_value_cansleep(port->rs485_rx_during_tx_gpio, > + !!(rs485->flags & SER_RS485_RX_DURING_TX)); > } > > static int uart_rs485_config(struct uart_port *port) > @@ -1407,7 +1409,7 @@ static int uart_rs485_config(struct uart_port *port) > int ret; > > uart_sanitize_serial_rs485(port, rs485); > - uart_set_rs485_termination(port, rs485); > + uart_set_rs485_gpios(port, rs485); Suggestion: define a new function to handle rx_during_tx, to keep uart_set_rs485_termination(), which is more self-documenting than uart_set_rs485_gpios(). ex: uart_set_rs485_termination(port, rs485); + uart_set_rs485_rx_during_tx(port, rs485); Hugo. > > ret = port->rs485_config(port, NULL, rs485); > if (ret) > @@ -1449,7 +1451,7 @@ static int uart_set_rs485_config(struct tty_struct *tty, struct uart_port *port, > if (ret) > return ret; > uart_sanitize_serial_rs485(port, &rs485); > - uart_set_rs485_termination(port, &rs485); > + uart_set_rs485_gpios(port, &rs485); > > spin_lock_irqsave(&port->lock, flags); > ret = port->rs485_config(port, &tty->termios, &rs485); > diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c > index 5e9cf0c48813..8eb13bf055f2 100644 > --- a/drivers/tty/serial/stm32-usart.c > +++ b/drivers/tty/serial/stm32-usart.c > @@ -226,10 +226,7 @@ static int stm32_usart_config_rs485(struct uart_port *port, struct ktermios *ter > > stm32_usart_clr_bits(port, ofs->cr1, BIT(cfg->uart_enable_bit)); > > - if (port->rs485_rx_during_tx_gpio) > - gpiod_set_value_cansleep(port->rs485_rx_during_tx_gpio, > - !!(rs485conf->flags & SER_RS485_RX_DURING_TX)); > - else > + if (!port->rs485_rx_during_tx_gpio) > rs485conf->flags |= SER_RS485_RX_DURING_TX; > > if (rs485conf->flags & SER_RS485_ENABLED) { > -- > 2.40.1 >