All of lore.kernel.org
 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 v6 9/9] serial: max310x: don't transmit while an RS485 reconfigure is pending
Date: Sun, 04 Oct 2026 12:31:06 +0000	[thread overview]
Message-ID: <20261004123107.045CC1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20261004-max310x-rs485-sw-delay-v6-9-3a0ef13ed9e3@vaisala.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] serial: nbcon lock imbalance due to raw spinlock guard bypassing uart_port_lock API
--

commit 5e3096e423054b0fa2875676ddddb86c4d77f052
Author: Tapio Reijonen <tapio.reijonen@vaisala.com>

serial: max310x: don't transmit while an RS485 reconfigure is pending

This commit defers RS485 transmissions while a reconfigure is pending to
prevent transmitting with a half-switched state. It adds a pending flag
evaluated under the port lock and restarts transmission once applied.

> diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
> index eb1d2e3bc870e..f8247cf0358ba 100644
> --- a/drivers/tty/serial/max310x.c
> +++ b/drivers/tty/serial/max310x.c
[ ... ]
> @@ -997,9 +1008,10 @@ static void max310x_start_tx(struct uart_port *port)
>  			uart_port_lock(port);
>  			/*
>  			 * The lock was dropped: a teardown may have run to
> -			 * completion meanwhile. Re-check before starting.
> +			 * completion or a reconfigure may have been posted
> +			 * meanwhile. Re-check before starting.
>  			 */
> -			if (one->tx_teardown)
> +			if (one->tx_teardown || one->rs485_pending)
>  				return;
>  		}
>  
[ ... ]
> @@ -1453,6 +1465,17 @@ static void max310x_rs_proc(struct work_struct *ws)
>  
>  	max310x_port_update(&one->port, MAX310X_MODE2_REG,
>  			    MAX310X_MODE2_ECHOSUPR_BIT, mode2);
> +
> +	/*
> +	 * The configuration is applied: release any TX that start_tx()
> +	 * deferred while the reconfigure was pending, now on the right path.
> +	 */
> +	scoped_guard(spinlock_irqsave, &one->port.lock) {
> +		one->rs485_pending = false;
> +		if (one->port.x_char ||
> +		    !kfifo_is_empty(&one->port.state->port.xmit_fifo))
> +			max310x_start_tx(&one->port);
> +	}
>  }

[Severity: High]
Will this scoped guard usage cause an unbalanced nbcon lock release and
subsequent leak when max310x_start_tx() is called?

max310x_rs_proc() acquires port.lock using a raw spinlock_irqsave guard,
bypassing the mandatory nbcon acquisition performed by the uart_port_lock()
API.

Inside max310x_start_tx(), if the timer cancellation fails, it temporarily
drops and reacquires the lock using the standard API:

max310x_start_tx()
    ...
    uart_port_unlock(port);
    hrtimer_cancel(&one->tx_delay_tmr);
    uart_port_lock(port);
    ...

When this sequence is reached via max310x_rs_proc(), uart_port_unlock() will
attempt to release an nbcon lock that was never acquired, and
uart_port_lock() will acquire it.

When max310x_start_tx() returns, the scoped guard in max310x_rs_proc() will
only release the raw spinlock, leaving the nbcon lock leaked. This can
permanently freeze the console or trigger lockdep crashes when a user space
process reconfigures RS-485 while a transmission delay timer is active.

Should this use the serial core uart_port_lock APIs instead of a raw
spinlock guard to ensure balanced locking?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261004-max310x-rs485-sw-delay-v6-0-3a0ef13ed9e3@vaisala.com?part=9

      reply	other threads:[~2026-10-04 12:31 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-04 12:16 [PATCH v6 0/9] serial: max310x: RS485 delay and RTS fixes, software-timed delays Tapio Reijonen
2026-10-04 12:16 ` [PATCH v6 1/9] serial: max310x: don't clobber the TX break bit in set_termios Tapio Reijonen
2026-10-04 12:23   ` sashiko-bot
2026-10-05 15:45   ` Hugo Villeneuve
2026-10-04 12:16 ` [PATCH v6 2/9] serial: max310x: assert the transceiver during a break Tapio Reijonen
2026-10-04 12:33   ` sashiko-bot
2026-10-04 12:16 ` [PATCH v6 3/9] serial: max310x: centralize the RS485 transceiver programming Tapio Reijonen
2026-10-04 12:24   ` sashiko-bot
2026-10-04 12:16 ` [PATCH v6 4/9] serial: max310x: convert RS485 delays from milliseconds to bit-times Tapio Reijonen
2026-10-04 12:30   ` sashiko-bot
2026-10-04 12:16 ` [PATCH v6 5/9] serial: max310x: wait for TX to drain before powering down in shutdown Tapio Reijonen
2026-10-04 12:28   ` sashiko-bot
2026-10-05 10:12   ` Maarten Brock
2026-10-05 10:51     ` Tapio Reijonen
2026-10-04 12:16 ` [PATCH v6 6/9] serial: max310x: support active-low RTS on the hardware path Tapio Reijonen
2026-10-04 12:25   ` sashiko-bot
2026-10-04 12:16 ` [PATCH v6 7/9] serial: max310x: schedule tx_work directly from the IRQ handler Tapio Reijonen
2026-10-04 12:24   ` sashiko-bot
2026-10-04 12:16 ` [PATCH v6 8/9] serial: max310x: drive RTS in software when hardware delays are too short Tapio Reijonen
2026-10-04 12:31   ` sashiko-bot
2026-10-04 12:16 ` [PATCH v6 9/9] serial: max310x: don't transmit while an RS485 reconfigure is pending Tapio Reijonen
2026-10-04 12:31   ` sashiko-bot [this message]

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=20261004123107.045CC1F00893@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.