From: sashiko-bot@kernel.org
To: "Tapio Reijonen" <tapio.reijonen@vaisala.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH v5 4/8] serial: max310x: wait for TX to drain before powering down in shutdown
Date: Tue, 29 Sep 2026 09:57:17 +0000 [thread overview]
Message-ID: <20260929095718.3DD811F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260929-max310x-rs485-sw-delay-v5-4-ae46afa583f2@vaisala.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] serial: max310x: local DoS via uninterruptible sleep in max310x_shutdown()
--
commit 4e0091905a683e3eb7b2b59d98c46ef3bed3cdef
Author: Tapio Reijonen <tapio.reijonen@vaisala.com>
serial: max310x: wait for TX to drain before powering down in shutdown
This commit modifies the max310x shutdown sequence to wait for the TX FIFO to
drain before powering down the port. It calculates a per-character duration
based on frame size and baud rate, then polls the TX empty status in a loop
to prevent truncating the final transmitted byte on close.
> diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
> --- a/drivers/tty/serial/max310x.c
> +++ b/drivers/tty/serial/max310x.c
[ ... ]
> @@ -1231,6 +1236,20 @@ static int max310x_startup(struct uart_port *port)
>
> static void max310x_shutdown(struct uart_port *port)
> {
> + struct max310x_one *one = to_max310x_port(port);
> + unsigned int loops = port->fifosize + 1;
> +
> + /*
> + * The tty layer waits for tx_empty() before close(), but tx_empty()
> + * only reflects the chip TX FIFO - the last character may still be in
> + * the transmit shift register. Let the FIFO drain and the final
> + * character clock out before the port is powered down, otherwise
> + * close() truncates the last byte on the wire.
> + */
> + while (!max310x_tx_empty(port) && loops-- > 0)
> + fsleep(one->one_char_duration_us);
[Severity: High]
Can this loop trigger a local denial of service or a hung task panic?
If a user configures a very low baud rate (e.g., 24 baud or lower), fills the
hardware TX FIFO, stops the receiver from reading (e.g., via hardware flow
control CTS), and closes the port, they can hit Ctrl-C to abort the TTY core's
interruptible uart_wait_until_sent() call. The execution path then proceeds
directly to max310x_shutdown().
Because this loop ignores signals and waits in uninterruptible sleep, bypassing
TTY layer timeouts, it forces the kernel to wait strictly on the baud rate. At
24 baud, one character takes ~416 ms, leading to ~53 seconds (129 iterations *
416 ms) of uninterruptible sleep while holding the port mutex. At 4 baud, the
sleep jumps to ~322 seconds, which immediately triggers the default 120-second
hung task watchdog.
> + fsleep(one->one_char_duration_us);
> +
> /* Disable all interrupts */
> max310x_port_write(port, MAX310X_IRQEN_REG, 0);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260929-max310x-rs485-sw-delay-v5-0-ae46afa583f2@vaisala.com?part=4
next prev parent reply other threads:[~2026-09-29 9:57 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
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 [this message]
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=20260929095718.3DD811F000FF@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