Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4019360rdb; Mon, 11 Dec 2023 06:50:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGU/4MMVxSW4VBa2TVkstLHzvAhLb1Xk+Kl/CZobjh0JW2rWjgGxFQ88Ny9ESjb6YtSJrR X-Received: by 2002:a05:6a00:985:b0:6ce:d486:657e with SMTP id u5-20020a056a00098500b006ced486657emr2512423pfg.10.1702306254126; Mon, 11 Dec 2023 06:50:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702306254; cv=none; d=google.com; s=arc-20160816; b=U+aDuEinVFa+nEiduR1JgydewsKz7Sx1BSptuHMpJ2gJ6GE23aEc49lRASGrFFmi+7 /n1o+SMu5ABaBK10vAcQOTXLAQ7c3I2LvNiz760uxvauGh22T5sCLn6QFNBVBFxoqWRF 3JlV6Usb+go3BppdBd3/OcKLhaldo1LYZxBhdmQTO9NC//kILQ4t5QQhIB89Hd5i8zfh E52iPZnRFWC6dBYvvppldL6Z5qkWsGSsMhhdLSLOCAGTYVUgx4FxcrX2l90I/JMQUZfR W5HGKmwmu3y+RpkrLRPeeaxL0KAA+YZhq8h5HrIbR2I959DwOqy4ksPP62L9F465IcJz +wIQ== 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=kEmVlye6CMrVPDyTmVFhOQ15lLv0MDG5hDAupVdWbcI=; fh=h+97kRpDipMFrUp90LNNeJwKj0S1FrV6aVDGOyQqEd8=; b=hIGMSSZcKcRV/xkMsL2tkGuyLS0Qf4p7vl70LJ3Ngd/TEGRu1dBI9FMkaAY72EKPSi Ur+nujzTKbqUhxbRvyOC8GYg1bbBKWN74CS8iVEy4ZIKcfoZ8MnDv/oxU9GLgktuFQbf 81HvtCrqm+ag+2tcIj4ec4u6VqICRYXxuUjAHa2ymn/ElyiX6qNRV0BPKlviUx1LdVMG ZftiJJHYpQboW3CLFyYxojjM9IUa+6L16y7n0m3x1oSrwA1+4XSgO1ZJhTb3pYihT3bl dDPAt9bxEMacFkQ8pwUD4VfxrSVX+/bxNYEhq0HVfqtV2nZJ8MVZ19zxD2Ubz4PsJ4EQ aKJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hugovil.com header.s=x header.b=gsXMqkQA; 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 Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id y11-20020a62f24b000000b006cb5f680e22si6109614pfl.389.2023.12.11.06.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 06:50:54 -0800 (PST) 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=@hugovil.com header.s=x header.b=gsXMqkQA; 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 Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id EEAAA807C868; Mon, 11 Dec 2023 06:50:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343701AbjLKOuA (ORCPT + 99 others); Mon, 11 Dec 2023 09:50:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234618AbjLKOuA (ORCPT ); Mon, 11 Dec 2023 09:50:00 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC2D0C3; Mon, 11 Dec 2023 06:50:05 -0800 (PST) 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=kEmVlye6CMrVPDyTmVFhOQ15lLv0MDG5hDAupVdWbcI=; b=gsXMqkQARmulOgWXmYNgBvmkpk 3QX7SSPv47Y/AVWozhPBPlR3/0omDCt9HHk4eqe6vmnzVKA7eVEaC4Koa0om8RkdVuOfFXTorn8uT 48s2HbOm9zme/QgYf6307hmA/tZ4eEF9MgEtFDUKBDlmtCuh2eu5hicPLqCCTdnl023w=; Received: from modemcable061.19-161-184.mc.videotron.ca ([184.161.19.61]:45548 helo=debian-acer) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1rChbI-0002gh-29; Mon, 11 Dec 2023 09:49:40 -0500 Date: Mon, 11 Dec 2023 09:49:38 -0500 From: Hugo Villeneuve To: Lino Sanfilippo Cc: gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com, 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, 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: <20231211094938.11c3322b80c2b827b46725c5@hugovil.com> In-Reply-To: <20231209125836.16294-2-l.sanfilippo@kunbus.com> References: <20231209125836.16294-1-l.sanfilippo@kunbus.com> <20231209125836.16294-2-l.sanfilippo@kunbus.com> X-Mailer: Sylpheed 3.7.0 (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: 184.161.19.61 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_CSS autolearn=unavailable autolearn_force=no version=3.4.6 Subject: Re: [PATCH v5 1/7] 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 (howler.vger.email [0.0.0.0]); Mon, 11 Dec 2023 06:50:16 -0800 (PST) On Sat, 9 Dec 2023 13:58:30 +0100 Lino Sanfilippo wrote: > Both the imx and stm32 driver set the rx-during-tx GPIO in rs485_config(). > Since this function 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 moving the GPIO setting outside of the port lock into > the serial core and thus making it a generic feature. > > 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: Shawn Guo > Cc: Sascha Hauer > Cc: stable@vger.kernel.org > Signed-off-by: Lino Sanfilippo > --- > drivers/tty/serial/imx.c | 4 ---- > drivers/tty/serial/serial_core.c | 12 ++++++++++++ > drivers/tty/serial/stm32-usart.c | 5 +---- > 3 files changed, 13 insertions(+), 8 deletions(-) > > diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c > index 708b9852a575..9cffeb23112b 100644 > --- a/drivers/tty/serial/imx.c > +++ b/drivers/tty/serial/imx.c > @@ -1943,10 +1943,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 f1348a509552..a0290a5fe8b3 100644 > --- a/drivers/tty/serial/serial_core.c > +++ b/drivers/tty/serial/serial_core.c > @@ -1402,6 +1402,16 @@ static void uart_set_rs485_termination(struct uart_port *port, > !!(rs485->flags & SER_RS485_TERMINATE_BUS)); > } > > +static void uart_set_rs485_rx_during_tx(struct uart_port *port, > + const struct serial_rs485 *rs485) > +{ > + if (!(rs485->flags & SER_RS485_ENABLED)) > + return; > + > + 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) > { > struct serial_rs485 *rs485 = &port->rs485; > @@ -1413,6 +1423,7 @@ static int uart_rs485_config(struct uart_port *port) > > uart_sanitize_serial_rs485(port, rs485); > uart_set_rs485_termination(port, rs485); > + uart_set_rs485_rx_during_tx(port, rs485); > > uart_port_lock_irqsave(port, &flags); > ret = port->rs485_config(port, NULL, rs485); > @@ -1457,6 +1468,7 @@ static int uart_set_rs485_config(struct tty_struct *tty, struct uart_port *port, > return ret; > uart_sanitize_serial_rs485(port, &rs485); > uart_set_rs485_termination(port, &rs485); > + uart_set_rs485_rx_during_tx(port, &rs485); > > uart_port_lock_irqsave(port, &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 3048620315d6..ec9a72a5bea9 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.42.0 > Reviewed-by: Hugo Villeneuve Hugo