Linux Serial subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tapio Reijonen" <tapio.reijonen@vaisala.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH v5 2/8] serial: max310x: assert the transceiver during a break
Date: Tue, 29 Sep 2026 09:56:05 +0000	[thread overview]
Message-ID: <20260929095606.208611F0089A@smtp.kernel.org> (raw)
In-Reply-To: <20260929-max310x-rs485-sw-delay-v5-2-ae46afa583f2@vaisala.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] serial: max310x: leaked RTS assertion if RS485 disabled mid-break
--

commit 7c2477330220cb7f9d2f88a0c967029ae3d062d8
Author: Tapio Reijonen <tapio.reijonen@vaisala.com>
serial: max310x: assert the transceiver during a break

This commit manually asserts the RTS bit during a break on RS485 ports,
as the auto-RTS mode does not assert it for non-FIFO data. It disables 
auto-RTS for the break duration, tracking the break status in a variable 
so the transceiver is restored when the break ends.

> diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
> index 4c1e10e0765f4..693decd04de10 100644
> --- a/drivers/tty/serial/max310x.c
> +++ b/drivers/tty/serial/max310x.c
[ ... ]
> @@ -929,9 +936,27 @@ static void max310x_set_mctrl(struct uart_port *port, unsigned int mctrl)
>  
>  static void max310x_break_ctl(struct uart_port *port, int break_state)
>  {
> +	struct max310x_one *one = to_max310x_port(port);
> +
> +	one->tx_break = break_state;
> +
>  	max310x_port_update(port, MAX310X_LCR_REG,
>  			    MAX310X_LCR_TXBREAK_BIT,
>  			    break_state ? MAX310X_LCR_TXBREAK_BIT : 0);
> +
> +	if (!(port->rs485.flags & SER_RS485_ENABLED))
> +		return;

[Severity: High]
If a userspace application starts a break (TIOCSBRK), and then disables
RS-485 (TIOCSRS485) before ending the break (TIOCCBRK), won't this early
return bypass the restoration of the RTS bit? Could this leak the manual RTS
assertion and leave the transceiver permanently driving the bus, causing
collisions?

> +
> +	/*
> +	 * The chip's auto-RTS asserts the transceiver only while FIFO data is
> +	 * shifting out, and a break is not FIFO data. Disable auto-RTS for the
> +	 * break duration and drive RTS manually so the break reaches the wire;
> +	 * restore auto-RTS when the break ends.
> +	 */
> +	max310x_port_update(port, MAX310X_MODE1_REG,
> +			    MAX310X_MODE1_TRNSCVCTRL_BIT,
> +			    break_state ? 0 : MAX310X_MODE1_TRNSCVCTRL_BIT);
> +	max310x_rts_ctl(port, break_state);
>  }
[ ... ]
> @@ -1055,6 +1080,13 @@ static void max310x_rs_proc(struct work_struct *ws)
>  	struct max310x_one *one = container_of(ws, struct max310x_one, rs_work);
>  	unsigned int delay, mode1 = 0, mode2 = 0;
>  
[ ... ]
> -	max310x_port_update(&one->port, MAX310X_MODE1_REG,
> -			MAX310X_MODE1_TRNSCVCTRL_BIT, mode1);
> +	/*
> +	 * A break owns the transceiver: break_ctl() disabled auto-RTS and
> +	 * drives RTS manually, and restores it when the break ends. Leave
> +	 * MODE1 alone meanwhile or the break goes undriven mid-way.
> +	 */
> +	if (!one->tx_break)
> +		max310x_port_update(&one->port, MAX310X_MODE1_REG,
> +				    MAX310X_MODE1_TRNSCVCTRL_BIT, mode1);

[Severity: High]
If the RS-485 state is changed mid-break, skipping this MODE1 update here 
means the transceiver might be left in the wrong state once the break
finishes. Should this new configuration be deferred or tracked so it can
be correctly applied when the break ends?

>  	max310x_port_update(&one->port, MAX310X_MODE2_REG,
>  			MAX310X_MODE2_ECHOSUPR_BIT, mode2);
>  }
> @@ -1090,6 +1128,7 @@ static int max310x_rs485_config(struct uart_port *port, struct ktermios *termios
>  
>  static int max310x_startup(struct uart_port *port)
>  {
> +	struct max310x_one *one = to_max310x_port(port);
>  	unsigned int val;
>  
>  	max310x_power(port, 1);
> @@ -1099,6 +1138,7 @@ static int max310x_startup(struct uart_port *port)
>  	 * closed with a break still asserted, and set_termios() no longer
>  	 * rewrites it.
>  	 */
> +	one->tx_break = false;
>  	max310x_port_update(port, MAX310X_LCR_REG, MAX310X_LCR_TXBREAK_BIT, 0);

[Severity: High]
While max310x_startup() correctly clears the latched TXBREAK bit here, does
it also need to clear the LCR_RTS_BIT? If a port is closed with an active
break, wouldn't the manual RTS assertion from max310x_break_ctl() remain
leaked on the next open?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260929-max310x-rs485-sw-delay-v5-0-ae46afa583f2@vaisala.com?part=2

  reply	other threads:[~2026-09-29  9:56 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29  9:37 [PATCH v5 0/8] serial: max310x: RS485 delay and RTS fixes, software-timed delays Tapio Reijonen
2026-09-29  9:37 ` [PATCH v5 1/8] serial: max310x: don't clobber the TX break bit in set_termios Tapio Reijonen
2026-09-29  9:49   ` sashiko-bot
2026-09-29 13:40   ` Hugo Villeneuve
2026-10-02  7:25     ` Tapio Reijonen
2026-10-02 15:03       ` Hugo Villeneuve
2026-10-04 10:45         ` Tapio Reijonen
2026-09-29  9:37 ` [PATCH v5 2/8] serial: max310x: assert the transceiver during a break Tapio Reijonen
2026-09-29  9:56   ` sashiko-bot [this message]
2026-09-29  9:37 ` [PATCH v5 3/8] serial: max310x: convert RS485 delays from milliseconds to bit-times Tapio Reijonen
2026-09-29 10:01   ` sashiko-bot
2026-09-29 13:54   ` Hugo Villeneuve
2026-10-01 19:11   ` Hugo Villeneuve
2026-10-02  7:27     ` Tapio Reijonen
2026-09-29  9:37 ` [PATCH v5 4/8] serial: max310x: wait for TX to drain before powering down in shutdown Tapio Reijonen
2026-09-29  9:57   ` sashiko-bot
2026-10-01 20:00   ` Hugo Villeneuve
2026-10-02  7:28     ` Tapio Reijonen
2026-10-02 15:01       ` Hugo Villeneuve
2026-10-04 10:56         ` Tapio Reijonen
2026-09-29  9:37 ` [PATCH v5 5/8] serial: max310x: support active-low RTS on the hardware path Tapio Reijonen
2026-09-29  9:56   ` sashiko-bot
2026-09-29  9:38 ` [PATCH v5 6/8] serial: max310x: schedule tx_work directly from the IRQ handler Tapio Reijonen
2026-09-29  9:58   ` sashiko-bot
2026-09-29  9:38 ` [PATCH v5 7/8] serial: max310x: drive RTS in software when hardware delays are too short Tapio Reijonen
2026-09-29 10:08   ` sashiko-bot
2026-09-29  9:38 ` [PATCH v5 8/8] serial: max310x: don't transmit while an RS485 reconfigure is pending Tapio Reijonen
2026-09-29 10:11   ` sashiko-bot
2026-10-01  8:35 ` [PATCH v5 0/8] serial: max310x: RS485 delay and RTS fixes, software-timed delays Greg Kroah-Hartman
2026-10-01  9:10   ` Tapio Reijonen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260929095606.208611F0089A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tapio.reijonen@vaisala.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox