From patchwork Thu Sep 28 22:12:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 727556 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41BB9E743CC for ; Thu, 28 Sep 2023 22:13:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232547AbjI1WNw (ORCPT ); Thu, 28 Sep 2023 18:13:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230325AbjI1WNv (ORCPT ); Thu, 28 Sep 2023 18:13:51 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A524019D; Thu, 28 Sep 2023 15:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1695939213; x=1696544013; i=linosanfilippo@gmx.de; bh=nLuCqydJpbT7/9fmhJ6R8xv1g0Gm3uYcudny9uknJvc=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=iMdIbDs6hkKyO856ypck2MXVe5QSCjVfBVZtwzeeo3qsdnLk0KaFYCX6cCcPWZc7C4B/TpruqPt 4A6ra1eTSbEIOEQRdZSWh5jd6V2/cEw7i2LsOKCjGvKgpeBUfF0lsdPRy/9xTpnqtNX+oWaP9L7DD qErLrh4tCmfG9Vm2h09MiDoVskACydDsxPo234Iycl6FMIGvCsXL7Bpl9Ey1lrzG/1j7xZcCQWGg4 YyfN0eLKCwRCNwAwwvGObHYQMQF17SHRLLW+Wh2MLryoF/OdWsSXTo+waRfPD7vgv84nxrY668Hpq RICKPpXJMrVm+OX3r8LU1mVsbx/d3RFRybKA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.21.41]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MTRR0-1rDNVw3oyq-00TnOw; Fri, 29 Sep 2023 00:13:32 +0200 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: shawnguo@kernel.org, s.hauer@pengutronix.de, ilpo.jarvinen@linux.intel.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com, stable@vger.kernel.org Subject: [PATCH 1/6] serial: Do not hold the port lock when setting rx-during-tx GPIO Date: Fri, 29 Sep 2023 00:12:41 +0200 Message-Id: <20230928221246.13689-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230928221246.13689-1-LinoSanfilippo@gmx.de> References: <20230928221246.13689-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:3LQwxQSDEDvmzvUu0aiddYpQ6pCaYOyJGCzvgx6N1RGoFucwpwd 3OBRNEhvnDQUFl3ZSJeLSpSHx6WPuD4ZC+TGJCE3NVcaVAAT7VizG1Qgpy7gFmsXUDF/8lo cAXHjM5NSa2V5YALy7fTQK4Yp67C3csXzbv8L3KHUNMikH1jm7yJJBgbKtBZEoGFjT/iON8 BhjCpmToMVvydbOSb3wXg== UI-OutboundReport: notjunk:1;M01:P0:4UOvIHl79A4=;Eoatoxh+nvzVe0uNQsm1zZ1tOjV 4aQyuaiODTgaMd68fC0bW3uCoO7z5ot+NwiDsqIgX12Rg8ucC/zS6K3V309p+3fF+Bw1Uk7KI drox1azOMHM/vq7Ubn6wAqVjQ97DQtUXw5QRLfIS+RytZ7IfO0wkSb9fk+8XIMT8yEykUCk9D X78uwN21LKE3lqPUWzvBbP6datfMNPfgX6bVNFdWEcmzj6Cnl9dno3LSzJ874btGg8/zumhUp pn8lP+9lt9AaEzjasDwSn9dTbBF2q4GbAjGYkC90sl0kDjU5zlhCIE5YIx1ZjYnHqrqUyBJsP wRtX56Tnwu2rpIJMBTOySi3UlWo7LD0gQKCumNO8NumryDvK0hY2Ib7mnYjUK9BGEZvtwluY6 dkOUmqxyss5mOLh0lC2y1mSN/AjCLK+MFPzJ1AS4+3V8KbZW+uqFJ5AzCAP4EJGlaQhvdbMp3 2LG7QGcjWJFU/VA/b8m4/G1RxZ1Slhg2m5J7+LzpsDUzG5ebHRsy/R7MGcFRZ/s90XZflM1H7 azTLULNgU+DrswSTBs7ffDSsOWS4EGyURcPntyo0W3/WTbXfiIOi8Hq4D5e12UYwdk5aAHE9a VjDCPD42LzXROlcoeTpQnX9vokKmRdpiTbR6QKndUrVR1qxmRve+4nTOT7W6Ewx4xLPVRfuZM uMrmAeAx9WtKVnSO7xp3r1kuz5gC/X+nWGvqNS+3YyfVaV1aPBs6fA/iMZmndJS7HHOr4EB06 3GpA07E7aEUuTln7YYwRzHnaA5WOzf7EGvJ524JIDQxuxOjg7DRRvfeq5Zf86+wNoXxFADGTQ /mq4bAG0imdfTsHCIyPeS69V0IIg0PD5rfY3yV6LjaDKJUgtIPWtUfvdGJQnLv2X3D52so/Xk SIc/ceRfVJKmxCqY22B6tzdmFI16wsZHLVYQR8Q6IFZqB4ja7uf0dYWyzAeprKk2f9NrsOjck 8SB5Qqpd4WoU4zNLwyBV/4eHrrU= Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Lino Sanfilippo 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(). 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. 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); 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) { From patchwork Thu Sep 28 22:12:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 728500 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F6D2E743CA for ; Thu, 28 Sep 2023 22:13:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232596AbjI1WN6 (ORCPT ); Thu, 28 Sep 2023 18:13:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232566AbjI1WNx (ORCPT ); Thu, 28 Sep 2023 18:13:53 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20C4F199; Thu, 28 Sep 2023 15:13:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1695939213; x=1696544013; i=linosanfilippo@gmx.de; bh=vJJdIPiNBx++tj9zJ3xfwS+JCLsCH3aBQui0XXS7z1o=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=ucN9AKNMnNjgF0t/G/lNHGfY+LK1qfKnY83u1TXeWTRQwfnn2F7A+hSl8/Mtlv7qVAKjpkzbwnX J27DI96ZfVigm+YEK9umV1V/4ZYip72tywJU0QBNZB3ysZBhUyQqKZZoQqOcNDU3ErLrED+ggy8XC kw7aS0UVBNpi5M4jsv+wupz4yNDIMjwCAaskNeK6/el8GVnqiO4kNHPoOXhgiWdqzxdubiVgKI+xG Z6pKInF5CCOvaQ9BT4HDnVWuukIliUwFGFYzjpQrc3VWoNW1PR7EDFTIi0pKaan7MHqjmvaGrgFpm nyrdgiOvlOckpKYGXIsuF7qOmWDYiymASnTg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.21.41]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1McH9i-1rM8tF0x2a-00chIk; Fri, 29 Sep 2023 00:13:33 +0200 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: shawnguo@kernel.org, s.hauer@pengutronix.de, ilpo.jarvinen@linux.intel.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH 2/6] serial: amba-pl011: get rid of useless wrapper pl011_get_rs485_mode() Date: Fri, 29 Sep 2023 00:12:42 +0200 Message-Id: <20230928221246.13689-3-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230928221246.13689-1-LinoSanfilippo@gmx.de> References: <20230928221246.13689-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:TpkKxtXsopZfiZUjpfsnzwKy/vXCM/Vs66OTnR8QnnHg11UC+ib /MXS/+n/r22VAEVPGicWkJpbejyF738VjNbNvsbUpmsGtcPE76CjoQcmIEbIr6shjNLK+ob 4kGco/DFP1HQxSC+ufkSTUeJD03TateVj312C0d9kGDjZWe/dC1+DCAI8pTTCJ6l+y9Jxla ijflsV4IFSiaRI4Cpgc3w== UI-OutboundReport: notjunk:1;M01:P0:g+IXyWx4S0s=;eXmYRB6me9QdFv/wdAED6xvpjP8 dWkkwOhhDhLlJubZMPVAGOUCzcijhC/0YmCiJRFxrOtxuc8FFCqDppHfkEF3d8SDlPCrDp84b juLlg3lhaySRX6P1cVVkQcNrBZMjECQ/MHCHmdt4zjR6RHbTBp7NBYfxL2vMcDEUofFuv/pPX FKUiGj71j/V7/BScIi85DOe5uX/vHyGTwt0fthwyFmZhxQVOmOXxs8lLv0ly7IX/0I5mTd3Ha mfpS5048peoCglxkxbXhsg3slVPyy6XPuobJcrWXvfU3m8jxwK4FsMYckYfT1yl8FpUaPG87u IY9/870PJ44PvTvPpIHDx36swSJobLMWquZUUDYxscNRB/ODhKGafF3T3kBGTTn8o90COzK49 D7zeMvjr4+paDpjbRaOMFhgVcGW6tqmcI4Cg+TUoqJKhhQxD25I12zzEwLSSDoXdiu5uLf0ML PPXrLq35UPKYHCccC7HHNi6mRF+rIqAuGJjaQHnUNYkYjrDv1Kn6EtMfE5qsCoYNZWVk3zEQN SRHH9282Wcv7WvFsYSsu7uaMW4d6MLJEEqcwd4KUktnGIvIN3OpRguLEduZESjCoFFwEmaj1M WvSfMkAcUjisKKr7zGNHsZK9WMW/wWkIvAmgiX888wYW/yjcKMWgZJRROewv1EcsxXrPAsHNo yEfk4XSuhztfBLPMzybfusEzXVR9hs3HQCjtrK3jAB2aXL0erwVZBWRtVu+008PrNQsXv3cx9 CrzOMWWx8E1m5zWLbh+YU3QkF7uRc0ovihCJhcP0b3HJZy8uLymy4H+4xPFGtFZpAVv5yBLKi 0Ac3RC9gV0TH+exyDVeuDyXVAxSf9NhToSJknwE3SdO4EgRmcFNiwHrRg0yj1VclK/PCOKkY2 iMAxrcoK/Kc7+qUCG+TQ6JxNjIzjOye/t5IN+8lQmTvIX4dgiJjUXYE9QPGquWKMGFJmWxXHH ehMKJQ== Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Lino Sanfilippo Due to earlier code changes function pl011_get_rs485_mode() is now merely a wrapper for uart_get_rs485_mode() which does not add any further functionality. So remove it and instead call uart_get_rs485_mode() directly. Signed-off-by: Lino Sanfilippo --- drivers/tty/serial/amba-pl011.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c index 3dc9b0fcab1c..70b44f3e9eb7 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -2716,18 +2716,6 @@ static int pl011_find_free_port(void) return -EBUSY; } -static int pl011_get_rs485_mode(struct uart_amba_port *uap) -{ - struct uart_port *port = &uap->port; - int ret; - - ret = uart_get_rs485_mode(port); - if (ret) - return ret; - - return 0; -} - static int pl011_setup_port(struct device *dev, struct uart_amba_port *uap, struct resource *mmiobase, int index) { @@ -2748,7 +2736,7 @@ static int pl011_setup_port(struct device *dev, struct uart_amba_port *uap, uap->port.flags = UPF_BOOT_AUTOCONF; uap->port.line = index; - ret = pl011_get_rs485_mode(uap); + ret = uart_get_rs485_mode(&uap->port); if (ret) return ret; From patchwork Thu Sep 28 22:12:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 727557 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45786E743C8 for ; Thu, 28 Sep 2023 22:13:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232507AbjI1WNv (ORCPT ); Thu, 28 Sep 2023 18:13:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231689AbjI1WNv (ORCPT ); Thu, 28 Sep 2023 18:13:51 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A46BA199; Thu, 28 Sep 2023 15:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1695939213; x=1696544013; i=linosanfilippo@gmx.de; bh=D/HyYToAkt8HPU01PSU5AsEnPHKGV/ERmzj/d7KZ9N8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=ocXHYEMymDm8AwrYH/9hMJ23Uqf+T7qGBDjofO6MnC6jsyI9U5leiSguquC9l1kvTHib+tl0cdQ fQrXMxJHX760iyvo/3dTfAyHkL/As0TTLkct/wT0qB/IX0qVitgP/WPI0aoZEGFb5J2NundoDdnE3 7n3pLfPgXCmeAzMqSO/7XykHQjHNVnZqbUu8Ec2r1cCZRMZXEIUtNAmD8Ag23loUyZBm8JhSPNKAA SMx3a7Co1HAwznwkRZaCAkJE2xvZEJJ57LySHnQLfV5G9eHFqmlr88Deh02T2mOmNVOt4hU+JhxSn qzf1GSMsoslAlTqyiK9+kLolOKsvjs+xcxAg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.21.41]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MnakR-1rSRUe28N3-00jWnv; Fri, 29 Sep 2023 00:13:33 +0200 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: shawnguo@kernel.org, s.hauer@pengutronix.de, ilpo.jarvinen@linux.intel.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com, stable@vger.kernel.org Subject: [PATCH 3/6] serial: core: set missing supported flag for RX during TX GPIO Date: Fri, 29 Sep 2023 00:12:43 +0200 Message-Id: <20230928221246.13689-4-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230928221246.13689-1-LinoSanfilippo@gmx.de> References: <20230928221246.13689-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:QcDgxfI6XE1Vgtej5E7fXsbYloK1SIkv9Fyxhooz1MfNM3zpbJY dmIGkalvdLuwTRffnp5MXVpTGMjkrwAjqGhNtMIPWW3jfOVMgkUh53zJo5NqE3I7gBTMFU6 0TEz6YrcUIRHEgU33k8I2vopmmvpX0nKH48r8xBZfn61yJmlOMnIe368suvkB7wImPQ6fkH rS5RpDyGpJ0JI7dmXuOcg== UI-OutboundReport: notjunk:1;M01:P0:Hrdkk3es4BE=;05suxLYMnno4mb/EG0e3AmVxk8n XvAqZj/RZb+iEJQs80GZbmaXK/a/NPFV/3wWWSVFKqwC5TJwqb7a+jwXCAn4ncxlyUVmfjaNZ gXToS8rzVUatV48BOYEpPJF9vRz+1PCU8ytIwX3QA0JO+zyMwzRj9PR9Y5szHfsJsjQcI+uEh 68FU12dVwiOdOfnSk2bKiXGLGxjFiO2IxJEbSK2AsRIWvBthT7xFXkET/86zF/nmOfaYbCGo/ 7asFxs+d64DBL6wYzKPxY629gQCeQgRx+07xrc5osq/WSWxRCUVX9S3DcgJZXVbjiJpDwXrgW r+ZbaORrrcuOog02YNd3XJa13GwMfiXesHh7qQngFkdtW9EAj2Pxc2C+yue8a1B3sJSHxfNmv rHqnpJpVdJcAir+dPGd0cPDeT6wpnnvrL9IK1/gbGvgqP/yb1aSYUbKM3FyeREsaZYIqTlR4m C2mLAkDlgzog1SeQIi5VKbJqpIBU+54wNB5Ab63pFGiRS8dGzdOxSXu6V4vt8+WRr0jYUrIOT mpw2DiKx+S0kxkVkfyjGoEQHRab8iBTZ7kCShrpGh0XR6EzAq7ptBjGJ9xD32DgxlhokdBUlp 0TbTRZi+E2dXvyCTyPCt1ls0Jzi6F4ihS+QmdB4PSQUXYLb/7unndXGwgEvD+lkp/zDmlHzCC l9lNaGukPE5Zg129OqVyFXzJSgKcdPcpM9MvdoSJYxtg5K5ZzPVYqn0eQ1RepFxuJZfbwDwLr lyY8IZ6JMcQHzZ/IOjEZoeA/T1sAP8U0fbjLM9ynI6hDwUUKuGfkgQmKVm12qO9yBpiBUpCAO q7hleiy/OIokeQv2IQv1IpGw/BrJVDWl632tT4mkLIG6AY/ClJVyeqYjmgM/OdPCls2vYuUac KHV8bHclUpLGY1pcFKv6ZfDBA4ye5ylua1zVz12HpCoMs3ZuVqkKa6r4bv/4x+2MzT2hjEj+k lt0q/Q== Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Lino Sanfilippo If the RS485 feature RX-during-TX is supported by means of a GPIO set the according supported flag. Otherwise setting this feature from userspace may not be possible, since in uart_sanitize_serial_rs485() the passed RS485 configuration is matched against the supported features and unsupported settings are thereby removed and thus take no effect. Cc: stable@vger.kernel.org Fixes: 163f080eb717 ("serial: core: Add option to output RS485 RX_DURING_TX state via GPIO") Signed-off-by: Lino Sanfilippo --- drivers/tty/serial/serial_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index ef0500be3553..697c36dc7ec8 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -3622,6 +3622,8 @@ int uart_get_rs485_mode(struct uart_port *port) port->rs485_rx_during_tx_gpio = NULL; return dev_err_probe(dev, ret, "Cannot get rs485-rx-during-tx-gpios\n"); } + if (port->rs485_rx_during_tx_gpio) + port->rs485_supported.flags |= SER_RS485_RX_DURING_TX; return 0; } From patchwork Thu Sep 28 22:12:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 727555 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3B12E743C9 for ; Thu, 28 Sep 2023 22:13:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232586AbjI1WNy (ORCPT ); Thu, 28 Sep 2023 18:13:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232552AbjI1WNw (ORCPT ); Thu, 28 Sep 2023 18:13:52 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B0CA1A2; Thu, 28 Sep 2023 15:13:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1695939214; x=1696544014; i=linosanfilippo@gmx.de; bh=mLPlHXBVRwexjH0Cj387VLbBgxjGGRTQWXTD7dFXyMo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=KQLdbtXKMqmvGK1Ic+BlRFgjsdhtMa+SeK206YXzV9aLWtvVG3MwcYgjKoUQbdH/5H+HEPQ/98h 1f1UIEEaRq5EDiw6QmnAWVRBvcQx68gSlSmUTr/UkFn0TcTKQULUDGuMPzXKglAf0dLIKKvUdQHDF lXFnkYn/j4gO3Fitg9FsTeqgd9n41FEoFphuA1tv9qHepmeadFE/N6F1Fe0Z3j2cnRwIEKtQprXWs 6ZG9jcFkQoEylmIWrz5ceHC8/f0HNyM96VfoJZ0Hu9h2jSCpuXAKuJ6O0qPjNZn34ICO116qDw5xu p7of6bPxWU+UB7SWibAFzsQrMnbBFOCVIIvg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.21.41]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mr9Fs-1rOqb53LEM-00oBVU; Fri, 29 Sep 2023 00:13:33 +0200 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: shawnguo@kernel.org, s.hauer@pengutronix.de, ilpo.jarvinen@linux.intel.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com, stable@vger.kernel.org Subject: [PATCH 4/6] serial: core: fix sanitizing check for RTS settings Date: Fri, 29 Sep 2023 00:12:44 +0200 Message-Id: <20230928221246.13689-5-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230928221246.13689-1-LinoSanfilippo@gmx.de> References: <20230928221246.13689-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:q5g0/t22Us9cn/lBgY6QmJyAiEQaNgtDtxjK+YvBOStqaS2nDfQ zMcTJuIMThPdRFuVaW1gtGcUHYDcWQvKrpC6sbHrpdTc/V83oLE6S/gf+SZ0WT8FwTubJLA AK73xikeMQpfk/RPyTmOERBOOoOQ2mVVMRJMrA3y9kR1A2XLWdNRW+68nf0BpeantrkOKqd HzcieTLxxlfeczVfyRNjQ== UI-OutboundReport: notjunk:1;M01:P0:bWWTFd2uhgo=;AAkMwugWAP0QngTop9gN+mtLifq oyiuk799766XqgO1K4PbKk23jcF3B5UPyv7QojPxbW84dCERYBzE82tpJ2XRNJOQTiq33W6uP Kx4lAHLq9tSkIDhtZI1xZINRU/aUpmv3x0kv8cp+zWk1BZeAQqfb58pFZm/h2h4SDCVObX/xO NCEw/yQjvvsLFuGV4ggzxESWWrLboDBgfdRmzeu1iMSzZaXNJcWSFv+3o7VldANvdjCkCBPq/ IWdbDI/zo8tQHvUaSkeARUL69JhN5kD7+ePl7gf8lullnbfeFZtwai07MJv5sKWqH780ZnXSj v0bQ3TUEKZVU7EH4g3Z19bMO49QcV+hdKI934bbjfJbuhv/1lbUgVLD/uTSMLHkiv+U7kbq/E pBF56nWaK+So+UhfZnf8KsRCqFYHdKG7boemqTncZZaJ7v1cqC/fhmjb3xS1DB5/dEn4W6pwy icTY2jlHJokKpaw7JX222AdC5uvyf1dPGXrrrSep0JsmQGU1ltFfcmH10I1KsOT6/hrNZetpR IxGm/3w5odmbxEJw+SVJwFsFAaz/NRodQdT4aTtG+mK/+g+ydEdYu4ojdNw4kq++SBW9tl4Z8 E2avaKu6wq1+mIrQjzjXTtsGodmjX2fOcEFOI5kbLMzD2mDLDAznVWq8YyfjK0LNGMD1wMlwe j5EJsUxowU9Q1r8UEtFKDIIgpUfnmtv8uSIVQUvHnTucjg/nfwF5WW2yEjLf5+TXbQ+XhIVK0 waMoQgJUB4KhvgCfJfxxhpk+D8JfZer+Bff0qEatMvwwxqVggY+SsGwTjaYbi2msKxl/dxZeR QzrM55e/IgDbEDWL5hQysiHe5Aet7imB+qyAFBQvMDTN1VV0wXCaCC1i3U/syBRf7PQI846UW lPMzRTeKhKDg+mmdMrQQk+A0oKcKcBifty4FS3PtRc4Pg8Dv9oRWNBDLIj0KmW6CKcvuNDfwV irpBEA== Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Lino Sanfilippo 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 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); From patchwork Thu Sep 28 22:12:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 727554 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 604DEE743CD for ; Thu, 28 Sep 2023 22:13:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232525AbjI1WN7 (ORCPT ); Thu, 28 Sep 2023 18:13:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232570AbjI1WNx (ORCPT ); Thu, 28 Sep 2023 18:13:53 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53DA91A3; Thu, 28 Sep 2023 15:13:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1695939214; x=1696544014; i=linosanfilippo@gmx.de; bh=hg8w75pV0e3pjbzQLJFWM+TM+iujlrT3Ta4nBCXoDzs=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=im686yKF1Pr+8T9GT14YLKy2cCDauXeY+iT4ymje2THJJk7u9j7Uge8hyl3oEPMXJcAauQXmX91 AFDdVBb+GoRvcxTu/8Z+/sZWdYpJAuDUDLs8l3ZvEraTB25HeE+c2zKZpF16a+M8o002ZDwgXpKF7 nD3wPOHaLK+Y77jsEUGDMtf1hyrplNC9fCPi5ZmogKhgyzM+OG8C+CvHJjqWRd4EwiPuFDsmYp5Pv an0H6Og+HttTsjmC2b5ZvdzO5ffeXi3N5gRW7bTNwoo307Yvze2UNCOeFZDOPialnUFOSH0v8ZtV4 dgX33wM8Hq/ad5/AQUZ3Th2972O37BdVsZqA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.21.41]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mi2Jn-1rGM8d0T8j-00e39X; Fri, 29 Sep 2023 00:13:34 +0200 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: shawnguo@kernel.org, s.hauer@pengutronix.de, ilpo.jarvinen@linux.intel.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com, stable@vger.kernel.org Subject: [PATCH 5/6] serial: core: make sure RS485 is cannot be enabled when it is not supported Date: Fri, 29 Sep 2023 00:12:45 +0200 Message-Id: <20230928221246.13689-6-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230928221246.13689-1-LinoSanfilippo@gmx.de> References: <20230928221246.13689-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Od3l4xl/uII61q4WCOzbzrdpV4WzfRrpfpwW+63udSex6TYzbGi Yxm3kzO8B0/p69CY6IbF6VIwdpcOC33Yh2uLfiUs2hUzzB+NvbzOW9K2YruY4zacovT56Qp wL/RFiJJTxVqsTJyhS/Yoo3m+FZdjOkPZDyRzr8yEqSw7cWa5e5YcWFsyzcAe3qXgQ3pum4 pHQH9QaYtUL+pSUgFKF2Q== UI-OutboundReport: notjunk:1;M01:P0:RERU25vI7eg=;t4JI+TeEd/T7kk73bmESiZA6A3d e+nOfxVI8YqeYeQsHbIdBiVKShltFe6hCz0O3OHfJUgXga3s/L/1+YxP2bLkHWLgUmG/OT1mS 85HokF0MpWKcS1GPpiR5M9N/RwrKRtcWomL73hBQrIldlsLPCqH1hVpi7EI4Ty2kvzszI4frv RMic0di7sMBEKE/eZCC253W2uYY2438RJUUt5LOC13TqXEWWiuJdNEIvfC/HklzfBnQjuBokM a2nhL8W1DWZWAy/dPzKx7gHIP1XoT5ErCk6Ko+MgNRPiOqHHVrlKAapbTM2iAMO5HmeBHnEQx /jVqJfUan0e9tCw6ZYyfU67qrJu02q8E8x7D2JlwT7IB9h8dN6F7aRamWD8VWgD/0zjTa0LUG Bjs3XcSdH8btnkAkkrzZuVW7vGQH0AiN/QPkATOhmC8jNwX0NDxqgME0wN4v+NX38w4nrTg87 oyuwiZxDz1Cm0OlTRN1yfChU2qhpZ1H3BPtbQa4N64U/VXO6KHuDqExNpc+3Yig2pW9VZVN6c 7YCHKmPLq1Ptitz8p4S+4S2zY8IR0MAGcwB4uXG6PqIP9i3fFaxF7PqRdGSQuZrV/WRH/wNeZ zkhChi6kImrBx1ca/O1Sr4k2dUQpS0cLinZELGozGoG84xw+RpGncvtNhA5nqlIAl6YFu6kdY FUhi4JyEUY8GP79ZBl5xoD32lMEu8xrxvYfAHPgZ37dR06CT5nDCiciui79BEatfS4dL2gmdS m5X/UEkJzAbJiqumPWeHL4IHArpH6xpU3PsFUAyWo+LvmfLGU5WYj6MH0PNEGTI75OR01Gmel ncbbCyKwiEUjJsXhjAmpX/H589Sh6U3p8ucbCmxNT3yvVKmPH5jTCbVZ2kPmQP9Q0Gd6aKlV+ cC7Og39gUqsA3fr810DFj5a0P/vahgn67Q1dsAS3amoamgoi+/mQI3V66s+Qk0IC6m2Y6hUTg oxM+XA== Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Lino Sanfilippo Some uart drivers specify a rs485_config() function and then decide later to disable RS485 support for some reason (e.g. imx and ar933). In these cases userspace may be able to activate RS485 via TIOCSRS485 nevertheless, since in uart_set_rs485_config() an existing rs485_config() function indicates that RS485 is supported. Make sure that this is not longer possible by checking the uarts rs485_supported.flags instead and bailing out if SER_RS485_ENABLED is not set. Furthermore instead of returning an empty structure return -ENOTTY if the RS485 configuration is requested via TIOCGRS485 but RS485 is not supported. Cc: stable@vger.kernel.org Signed-off-by: Lino Sanfilippo --- drivers/tty/serial/serial_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index f4feebf8200f..dca09877fabc 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1432,6 +1432,9 @@ static int uart_get_rs485_config(struct uart_port *port, unsigned long flags; struct serial_rs485 aux; + if (!(port->rs485_supported.flags & SER_RS485_ENABLED)) + return -ENOTTY; + spin_lock_irqsave(&port->lock, flags); aux = port->rs485; spin_unlock_irqrestore(&port->lock, flags); @@ -1449,7 +1452,7 @@ static int uart_set_rs485_config(struct tty_struct *tty, struct uart_port *port, int ret; unsigned long flags; - if (!port->rs485_config) + if (!(port->rs485_supported.flags & SER_RS485_ENABLED)) return -ENOTTY; if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user))) From patchwork Thu Sep 28 22:12:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 728501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26368E743D0 for ; Thu, 28 Sep 2023 22:13:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232584AbjI1WNx (ORCPT ); Thu, 28 Sep 2023 18:13:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232527AbjI1WNv (ORCPT ); Thu, 28 Sep 2023 18:13:51 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FE3D1A1; Thu, 28 Sep 2023 15:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1695939214; x=1696544014; i=linosanfilippo@gmx.de; bh=m4weqzXnsQgnMts6TFaFYqbOaRUWzpTcPEjf6E+HoPM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=O2K6GDBcsvy/X7k3qNvCuY6yHPhAHspkfoSpIamF6aP3/YSxuXb6rvD/AAePbgSvoGI5tOJSqXY IpHIdujPHZdGZ5S5pF4pG6zBlOf+rZcpMrzyGugN+b1QSHSIsMRbPKamFt2Xzjk5LWXaeYeFXO7Vl TL8QL04aV3NiQtKqIacdorilnWlCXDTz5jPNtPz2+VXufzhDl2EWzKklwyzwTlHqmVmT1QzyW8jlK YpkjfOGXvpJhBoB+S5D23WTqbEyf6dIIUxcdIxooHPZwVn3owJFsz+hYsXPyRg/DjTrwV2wcWz6FV R9ezsBBaQGlvjvnDiV6I4DqAat2TB7PrarDg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.21.41]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MVvL5-1rAufz2U8D-00RrSh; Fri, 29 Sep 2023 00:13:34 +0200 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: shawnguo@kernel.org, s.hauer@pengutronix.de, ilpo.jarvinen@linux.intel.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH 6/6] serial: imx: do not set RS485 enabled if it is not supported Date: Fri, 29 Sep 2023 00:12:46 +0200 Message-Id: <20230928221246.13689-7-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230928221246.13689-1-LinoSanfilippo@gmx.de> References: <20230928221246.13689-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:+P81Kmr4hyoqergClf8xEE8mnhWpYVoCtypzwglXZWjyGqQWYLH RQKuksnXluP2TFFn63tcKtyOy8tLk5h25mkqMuMACecbLZ/rnIOLR3pyzsfY+N/+ye2fuUr /umOamJl3sJpsfNyWime4++fMNirZ3gwGxenxVq1c4BpOUi40fBiAHlhMpZioQZGNpt15bB r/qBmq/LmoQCrbla6OjHw== UI-OutboundReport: notjunk:1;M01:P0:SaxcjmS9I4U=;tOhBjxhnZQ7yIMQ44q84IDoko7I +6nOqPJefUEWR6mxq0+Ty2mlVmTeSscj5yL8lvJitdT+bw23I5tjS8Ff066yzD5TqNCH5MfxA MCLe/k2zmw9QLMRM49RZEYLutlLz1Hio6BPmmb79N/ToG7DjC6nq5w42twqAwpr1KSTmF83Rv AgW7W0m60pAKjDY4URiPB5FVuTEpNT5o59ej5f7+divlzQq8NPDR083xAvqdxBGpxpLByGlPq eEnLAP6c9RVP/xkKImXpfTr2un23yJoXskFBsv2sBCwgrkdD3x20ChAvmRE9IRVI4CDSB+IRq vVTpd9NcB0rbIbq/+Ezbca2DMrNfoHh1tkXUKYFoPKT9PLIeY1cYVWx7/yt46ETTlF9qYSq34 4XQPdjqcsqNRGkC0Jva2murcKazTu9W92UGWpc6YutjcZ3DgSihzQ1UYqdnT4e2jnbdc7GQLq p36J3m8PcqpTHa26HmqjjD3c3PFfoIh8rhmDh/JiuJNEZOYXzhoX2gbELHwn6KuDB8jCvy/aV n7oPv4sMZYqoYcZ+keA3VCC7khwrmuja7voUpF5eo0ocA9rP4FLwEtwxGcotStxD/wyKTgeRA qbSMAp3xh3z+5DzO3VZT5ghVQOWRsfJ4uSMetn76wXkK1ZOChx2O41Iyt/Am751pFl1YkK85m XVlqaYthFaPe9xIeQfctlBY+AzbiXAmb/Fe2KIMmxYUIXxEiFNu5klZJZMV6xzLO6Ddh/noL7 X1F/MzRQKcVec6S1tFrX2RNP+uYD8ypt6qGJdnAtipfu8ppGrxUK4WQKgIq4ZymroQzzI1Rwn OGFQfDavflKn2vd12dd1uD/ThLPTNLFtZ+ekkzID9rCik9laKWfUPvXtz1xUYvqBGlfAgdatj uTnJV20CDfx5MOugZYxknlDxSH3qNoKjypubfh7PaE4qVCSmuJDU9CeWdV17VAEDllccuYpno UYS4LPQtjjsvM72QBWS0jL/8+7k= Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Lino Sanfilippo If the imx driver cannot support RS485 it sets the UARTS rs485_supported structure to NULL. But it still calls uart_get_rs485_mode() which may set the RS485_ENABLED flag. The flag however is evaluated by the serial core in uart_configure_port() at port startup and thus may lead to an attempt to configure RS485 even if it is not supported. Avoid this by calling uart_get_rs485_mode() only if RS485 is actually supported by the driver. Remove also a check for an error condition that is not possible any more now. Signed-off-by: Lino Sanfilippo --- drivers/tty/serial/imx.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index edb2ec6a5567..87689abc21bd 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -2326,16 +2326,14 @@ static int imx_uart_probe(struct platform_device *pdev) return ret; } - ret = uart_get_rs485_mode(&sport->port); - if (ret) { - clk_disable_unprepare(sport->clk_ipg); - return ret; + if (sport->port.rs485_supported.flags & SER_RS485_ENABLED) { + ret = uart_get_rs485_mode(&sport->port); + if (ret) { + clk_disable_unprepare(sport->clk_ipg); + return ret; + } } - if (sport->port.rs485.flags & SER_RS485_ENABLED && - (!sport->have_rtscts && !sport->have_rtsgpio)) - dev_err(&pdev->dev, "no RTS control, disabling rs485\n"); - /* * If using the i.MX UART RTS/CTS control then the RTS (CTS_B) * signal cannot be set low during transmission in case the