From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796548531; b=qMpJfwYNwSWcbMLYEh1exuiGOrfne7MwqK16fA/aucFU8DyRoBL2/5qofJGba9payGrF EAYG/eF5f+jiWoFHstoreSwqaG6PV4i1edSByhDQojrkcCWwjPEgoMVDnJbQADvKLaXpl hSrSKnZT9L6Sy8pXXDYy9HBZG9h7RAuOVEfSo5h78G3pMGpk7xKm0eHrmzVW8nIymQLQ0 ht5IXlMdYghapFD7aYeqKrdSkDeDpKRvUGp0r4F/vheTqxqVJHoUTABY8OIM8DeaDgf5M wmyosIcQgzFUxuNCtJRRkVkGn8XwyvsgwccwCBjAXiRQcN52huSkCNFQ/uvkdtqNfeQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796548531; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=3P1FBG+H71IyJT+wzt1ffy8DJdEOMUX9In9cbiQLm+Q=; b=Wzv2SKTIVQH27UBs/Cj3IPVuMkL0xwfB+n9bO62QGqtCj9RxfsTdwyMg/S5PNv6l5g31 q1TXWW6pescyc/O50LpywoB1AlqKo8gv8qflYm+3VbjsR+2FcIf3RGQPqd3fm/9+m7zz2 ZnjbZbpJTcKNP2YML+V8ARWFQP4P/G06/YjpKOYSEWm3+h3iyNBgjAtwawCuoojIpyfco Kv1gx01IS5o3bvRv+5VB7rv4EIG9mNis02rYWFG3wf8agCgP7+BR+Qcj/fpXgjcNVcf3T pnHp8+kRdQbB63iqEolUbeEKfifCoBV5PGgGEvgguW13SNgPE2Tt+U98056bNdBDJpQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IWagxWAB; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 853E8606A321; Sun, 6 Dec 2026 09:15:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IWagxWAB Received: by smtp.kernel.org (Postfix) with ESMTPSA id 197181F0092B; Sun, 6 Dec 2026 09:15:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796548531; bh=3P1FBG+H71IyJT+wzt1ffy8DJdEOMUX9In9cbiQLm+Q=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=IWagxWABiZ22/WnfkRVMC6q6EMcFz+IhCfjC1iTkEBZO3hg61WdttK2Jv93Z2cci+ A4KWN6mbWu7KT2OJTU9MSd92PkYkk7tLl8K5AWcAG2duSYPvCphE/V5gkf0uK6pXdw w0IEHU9mT5ufE64HQB6PorrSQ4bOsFtgXcXGrCkfK1BazMXHO2sntl9tIjQgLXz71H y9+IJh627cVglybyCsZ8vD5WLvoQWw+EbGRtjR3Sbh1UL9jn6dLIsKrmYH5HduYQeE DtMq0Im234DAF6WagjFvAdackpNtdytY6Hf+NiI8wmrDz6fa1I0KZbSHZhPzPWZj5J zCwZtnGi0Zdvg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RESEND v2 3/3] serial: core: Drive the transceiver interface select GPIO Reply-To: sashiko-reviews@lists.linux.dev To: "Tapio Reijonen" Cc: linux-serial@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261206-serial-rs485-mode-gpio-v2-3-b9ea0dc2af3a@vaisala.com> References: <20261206-serial-rs485-mode-gpio-v2-0-b9ea0dc2af3a@vaisala.com> <20261206-serial-rs485-mode-gpio-v2-3-b9ea0dc2af3a@vaisala.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 09:15:30 +0000 X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] serial: rs485_select_gpio driven before async rs485_config() parks RTS - [Medium] serial: uart_set_rs485_config() leaves rs485_term_gpio high on disable - [Medium] serial: core: set_mctrl() runs before uart_rs485_config() leaves RS485 -- commit 42e26c01d500a86e5f47a0d41e2915cadf1d5b27 Author: Tapio Reijonen serial: core: Drive the transceiver interface select GPIO This commit adds an optional rs485-select-gpios property to uart_get_rs485_mode() and drives it from uart_rs485_config() and uart_set_rs485_config() to select between RS485 and an alternative transceiver interface. > diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial= _core.c > index 9516f50a72139..6c0a6d9dcb851 100644 > --- a/drivers/tty/serial/serial_core.c > +++ b/drivers/tty/serial/serial_core.c [ ... ] > @@ -1446,13 +1447,22 @@ static void uart_set_rs485_rx_during_tx(struct ua= rt_port *port, > !!(rs485->flags & SER_RS485_RX_DURING_TX)); > } > =20 > +static void uart_set_rs485_select_gpio(struct uart_port *port, > + const struct serial_rs485 *rs485) > +{ > + gpiod_set_value_cansleep(port->rs485_select_gpio, > + !!(rs485->flags & SER_RS485_ENABLED)); > +} > + > static int uart_rs485_config(struct uart_port *port) > { > struct serial_rs485 *rs485 =3D &port->rs485; > int ret; > =20 > - if (!(rs485->flags & SER_RS485_ENABLED)) > + if (!(rs485->flags & SER_RS485_ENABLED)) { > + uart_set_rs485_select_gpio(port, rs485); > return 0; > + } [Severity: Medium] Does uart_configure_port() drive RTS via set_mctrl() before this path takes the transceiver out of RS485 mode? When rs485-select-gpios is strapped active and linux,rs485-enabled-at-boot-time is not set, uart_get_rs485_mode() keeps the select line active through probe. uart_configure_port() then calls port->ops->set_mctrl(port, port->mctrl) before uart_rs485_config(). On drivers where clearing TIOCM_RTS drives the physical RTS/DE pin high (such as imx_uart_set_mctrl() or pl011_set_mctrl()), that enables the RS485 driver onto the shared bus until gpiod_set_value_cansleep() switches the transceiver to the alternative interface. Deasserting rs485_select_gpio before set_mctrl() in uart_configure_port(), matching uart_set_rs485_config(), would avoid the glitch. [ ... ] > @@ -1503,6 +1515,10 @@ static int uart_set_rs485_config(struct tty_struct= *tty, struct uart_port *port, > uart_set_rs485_termination(port, &rs485); > uart_set_rs485_rx_during_tx(port, &rs485); > =20 > + /* Leave RS485 before RTS reverts to modem control below */ > + if (!(rs485.flags & SER_RS485_ENABLED)) > + uart_set_rs485_select_gpio(port, &rs485); [Severity: Medium] Does disabling RS485 here leave rs485_term_gpio asserted after switching to the alternative interface? When userspace enables RS485 with SER_RS485_TERMINATE_BUS and later disables RS485 via TIOCSRS485, uart_set_rs485_termination() returns early because SER_RS485_ENABLED is clear. uart_set_rs485_select_gpio() then switches the transceiver to RS232 on the same bus pins while rs485_term_gpio stays high and TIOCGRS485 reports termination off. On boards where termination is not internally gated by the select pin, the resistor stays connected across the RS232 lines and overloads the driver. Dropping the early return in uart_set_rs485_termination() would clear it, since uart_sanitize_serial_rs485() already clears the flag. [ ... ] > + /* Enter RS485 only once the driver has parked RTS */ > + if (rs485.flags & SER_RS485_ENABLED) > + uart_set_rs485_select_gpio(port, &rs485); [Severity: Medium] Can uart_set_rs485_select_gpio() here (and in uart_rs485_config()) enable RS485 before drivers with asynchronous rs485_config() callbacks park RTS? SPI/I2C drivers such as max310x and sc16is7xx call uart_get_rs485_mode() but defer hardware setup to a worker because port->rs485_config() runs under port->lock. In max310x, the worker blocks on port->mutex, which serial_core holds across the GPIO update: uart_ioctl() kworker (max310x_rs_proc) mutex_lock(&port->mutex) uart_set_rs485_config() max310x_rs485_config() schedule_work(&one->rs_work) mutex_lock(&port->mutex) <-- blocks uart_set_rs485_select_gpio() <-- RS485 enabled with unparked RTS mutex_unlock(&port->mutex) max310x_set_rts_ctl_params() sc16is7xx_config_rs485() similarly queues reg_work on s->kworker and races with uart_set_rs485_select_gpio(). If RTS is asserted from RS232 modem control on an open port, switching to RS485 before the worker parks RTS enables the RS485 transmitter onto the shared bus. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261206-serial-rs4= 85-mode-gpio-v2-0-b9ea0dc2af3a@vaisala.com?part=3D3