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=1796548771; b=OCLCy+4fYeqOIfDjty86bY+PvqNJmaWtQchncDThrh8ZcPP0FkSyJQoM5lyxfPkReRxa SQsMIc385YGWkeFXwSlbD/w0rLrLEkgFlFmdW6zogLacYrS0uT9kq3dVWciSNlET2yWLv rgi8bw9LZk9X9zNGfuqFBbyYzEX1CcXnHIMJtjKWUpEGjYAgMH/ktO6oAQBeyr4lKG7Eu VIxX0khUuZHpJ8I3kUvom7k0g+QEg/XfyYJ3kpiKOF898/0/YfgIaAoaCy5XA/BEeOczV 0FBApUWUWKRgxHkixqCaGjlcuROrZjhrKXF141PzeoXFVFaqBm9sF2Cpz6q+ElzQslg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796548771; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=4+gn+BwpqlEXwRnup8mPBNbCC5K7gzgjN2XE6CPT4t8=; b=uZr1N8trvorEiC372UCs6MSos9ZyRSogdsgnIDPSbzRyX4zbzegHARy4vNzf0Isu5V/t xOMgDc/OpxWgrYoheaSncfbpyOLh1cgl5CmlC40xyswgd2+796CqMD0YJtp8u3q/X3eED 5hZg7nwohBJGlFO0KEgLbdQe/7S3knnwt9MOLZuau4zP8TzzhNXCORawGIjfSn6IAd81c 6mpQhBFMtoFRgvydmZYrDXoQERfl59SWwWNLScDmcOSw2Ek+QgU4k4zPMevNX8hrT0STt HAhqHKXdi5I62u9HXPZ+JmTvnGrZiL8BoF4WEuHcieAg7eJ2GIpywJwxu4pWanY70Ig== 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=kQ5KptRW; 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 923D3606A321; Sun, 6 Dec 2026 09:19:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kQ5KptRW Received: by smtp.kernel.org (Postfix) with ESMTPSA id 284881F00A07; Sun, 6 Dec 2026 09:19:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796548771; bh=4+gn+BwpqlEXwRnup8mPBNbCC5K7gzgjN2XE6CPT4t8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=kQ5KptRWxkyDhqbBm7sMHvQm/35KywKVU35U9YX2RBApMwy3SEUpiZPqERJc6TWA6 hPVFntTieUmzrcmvZLCcFgP7M1LFotmhSRZWpqfJ+zh854Yj38wU81K0VOzdm1sQNJ COQF1Ide7Et3zBGhRi5hZeBuriXPvZh0hzECbOGHS2wnEi03yvaTYxHhID+gCfks1t r/RAJOBW3voaf8eaDcoF9OIe4ArpAb5m6TcMga/9IP9nsjBj7MbiE2n26O221tZ7r+ WriMZapC6bIxhc5IIi8W3lCW9/OwubtMl9Opg317j9ro+UoT0zfy8oDK/rx4WTmR0H WYINzvsdQv7ww== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RESEND v2 1/3] serial: core: Forget the RS485 GPIO descriptors when a port is removed 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-1-b9ea0dc2af3a@vaisala.com> References: <20261206-serial-rs485-mode-gpio-v2-0-b9ea0dc2af3a@vaisala.com> <20261206-serial-rs485-mode-gpio-v2-1-b9ea0dc2af3a@vaisala.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 09:19:30 +0000 X-Mailing-List: devicetree@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: core: unlocked uart_forget_rs485_gpios() before refcount drain - [Low] serial: core: missing Fixes trailers for RS485 GPIO commits - [Low] serial: core: redundant uart_forget_rs485_gpios() call on error path -- commit 31b880969cda7f2c09673a8a1805582d0de68b47 Author: Tapio Reijonen > serial: core: Forget the RS485 GPIO descriptors when a port is removed > > The RS485 termination and RX-during-TX GPIO descriptors are acquired > with devm on behalf of the port's device in uart_get_rs485_mode() and > stored in struct uart_port, but nothing ever clears them. A uart_port > can outlive the device it was registered with: the 8250 core keeps its > ports in a static array, re-adds an unregistered entry as a placeholder > and hands it to the next device that claims the slot. If that device > has no RS485 support or no firmware node, uart_get_rs485_mode() returns > before acquiring anything and the stale descriptors stay in place, > pointing at lines that devres has already released. Enabling RS485 on > such a port then drives GPIO lines the port no longer owns. The same > happens when uart_get_rs485_mode() itself fails after the first > descriptor was acquired. > > Forget the descriptors when a port is removed, on entry to > uart_get_rs485_mode() and on its error paths, so a port only ever > carries descriptors acquired for its current device. > > Signed-off-by: Tapio Reijonen [Severity: Low] This fixes stale devm-managed RS485 GPIO descriptors across port removal and re-probe. Should this include Fixes: tags for the commits that introduced them? Fixes: d58a2df3d887 ("serial: 8250: Support rs485 bus termination GPIO") Fixes: 163f080eb717 ("serial: core: Add option to output RS485 RX_DURING_= TX state via GPIO") > diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial= _core.c > index c0deec0e6af41..9516f50a72139 100644 > --- a/drivers/tty/serial/serial_core.c > +++ b/drivers/tty/serial/serial_core.c [ ... ] > @@ -3265,6 +3276,7 @@ static void serial_core_remove_one_port(struct uart= _driver *drv, > */ > uport->type =3D PORT_UNKNOWN; > uport->port_dev =3D NULL; > + uart_forget_rs485_gpios(uport); > =20 > guard(mutex)(&port->mutex); > WARN_ON(atomic_dec_return(&state->refcount) < 0); [Severity: Medium] Can clearing the RS485 GPIO pointers before taking port->mutex and draining state->refcount race with concurrent ioctls on /dev/console? When the removed port is the active console, tty_port_tty_vhangup() keeps console_fops and skips uart_hangup(), leaving TTY_IO_ERROR unset. Before port->mutex is re-acquired and state->refcount is drained, a TIOCSRS485 ioctl on /dev/console can still enter uart_set_rs485_config(): CPU0 CPU1 serial_core_remove_one_port() tty_port_tty_vhangup() /* /dev/console keeps console_fops */ unlock(&port->mutex) uart_ioctl(TIOCSRS485) lock(&port->mutex) uart_set_rs485_config() uart_forget_rs485_gpios(uport) uport->rs485_term_gpio =3D NULL; gpiod_set_value_cansleep( port->rs485_term_gpio, ...) <-- data race lock(&port->mutex) wait_event(... !refcount) state->uart_port =3D NULL This causes a data race on the RS485 GPIO pointers and can leave the GPIOs in an inconsistent state if uart_set_rs485_config() rolls back on error. Moving uart_forget_rs485_gpios(uport) inside the mutex guard after wait_event() and state->uart_port =3D NULL closes the race. > @@ -3579,6 +3591,8 @@ int uart_get_rs485_mode(struct uart_port *port) > u32 rs485_delay[2]; > int ret; > =20 > + uart_forget_rs485_gpios(port); > + > if (!(port->rs485_supported.flags & SER_RS485_ENABLED)) > return 0; > =20 > @@ -3628,8 +3642,11 @@ int uart_get_rs485_mode(struct uart_port *port) > * Works fine for short cables and users may enable for longer cables. > */ > desc =3D devm_gpiod_get_optional(dev, "rs485-term", GPIOD_OUT_LOW); > - if (IS_ERR(desc)) > - return dev_err_probe(dev, PTR_ERR(desc), "Cannot get rs485-term-gpios\= n"); > + if (IS_ERR(desc)) { > + uart_forget_rs485_gpios(port); > + return dev_err_probe(dev, PTR_ERR(desc), > + "Cannot get rs485-term-gpios\n"); > + } [Severity: Low] Is this uart_forget_rs485_gpios() call redundant? The function already cleared both GPIO pointers on entry and has not assigned either one yet. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261206-serial-rs4= 85-mode-gpio-v2-0-b9ea0dc2af3a@vaisala.com?part=3D1