Linux Serial subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Samarth Narang" <samarth.colleges@gmail.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH 2/2] tty: serial: samsung: do not re-arm RX DMA once RX has been stopped
Date: Sat, 31 Oct 2026 01:03:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-191689@kernel.org> (raw)
In-Reply-To: <20261031004217.3340610-3-samarth.colleges@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] tty: serial: samsung: s3c24xx_serial_rx_chars_dma() ignores rx_enabled
--

commit 487da6105041ec489b81c069edfdd379610e15fb
Author: Samarth Narang <samarth.colleges@gmail.com>

tty: serial: samsung: do not re-arm RX DMA once RX has been stopped

This commit prevents s3c24xx_serial_rx_dma_complete() from re-arming RX DMA
after ourport->rx_enabled has been cleared, and clears ourport->rx_enabled
under the port lock during s3c64xx_serial_shutdown().

Link: https://lore.kernel.org/r/20261030162334.3000737-1-samarth.colleges@gmail.com

> diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
> index 2f6c69beccb74..3f2346f4fd0a9 100644
> --- a/drivers/tty/serial/samsung_tty.c
> +++ b/drivers/tty/serial/samsung_tty.c
> @@ -622,7 +622,8 @@ static void s3c24xx_serial_rx_dma_complete(void *args)
>  		tty_kref_put(tty);
>  	}
>  
> -	s3c64xx_start_rx_dma(ourport);
> +	if (ourport->rx_enabled)
> +		s3c64xx_start_rx_dma(ourport);
>  
>  	uart_port_unlock_irqrestore(port, flags);
>  }
> @@ -1165,10 +1166,13 @@ static void s3c24xx_serial_release_dma(struct s3c24xx_uart_port *p)
>  static void s3c64xx_serial_shutdown(struct uart_port *port)
>  {
>  	struct s3c24xx_uart_port *ourport = to_ourport(port);
> +	unsigned long flags;
>  
> +	uart_port_lock_irqsave(port, &flags);
>  	ourport->tx_enabled = 0;
>  	ourport->tx_mode = 0;
>  	ourport->rx_enabled = 0;
> +	uart_port_unlock_irqrestore(port, flags);

[Severity: High]
Does s3c24xx_serial_rx_chars_dma() also need to check ourport->rx_enabled
after acquiring the port lock?

In drivers/tty/serial/samsung_tty.c, s3c24xx_serial_rx_chars_dma() reads
S3C2410_UTRSTAT before acquiring uart_port_lock(port), and then proceeds
without checking whether ourport->rx_enabled is still set:

drivers/tty/serial/samsung_tty.c:s3c24xx_serial_rx_chars_dma() {
	utrstat = rd_regl(port, S3C2410_UTRSTAT);
	rd_regl(port, S3C2410_UFSTAT);

	uart_port_lock(port);

	if (!(utrstat & S3C2410_UTRSTAT_TIMEOUT)) {
		s3c64xx_start_rx_dma(ourport);
		if (ourport->rx_mode == S3C24XX_RX_PIO)
			enable_rx_dma(ourport);
		goto finish;
	}

	if (ourport->rx_mode == S3C24XX_RX_DMA) {
		dmaengine_pause(dma->rx_chan);
		dmaengine_tx_status(dma->rx_chan, dma->rx_cookie, &state);
		dmaengine_terminate_all(dma->rx_chan);
		received = dma->rx_bytes_requested - state.residue;
		s3c24xx_uart_copy_rx_to_tty(ourport, t, received);

		enable_rx_pio(ourport);
	}
}

If an RX interrupt fires on another CPU and spins on port->lock while
s3c24xx_serial_stop_rx() or s3c64xx_serial_shutdown() clears
ourport->rx_enabled (especially during s3c64xx_serial_shutdown(), where
S3C64XX_UINTM is only masked after free_irq()), s3c24xx_serial_rx_chars_dma()
can enter the critical section after ourport->rx_enabled is 0.

When S3C2410_UTRSTAT_TIMEOUT is not set, s3c24xx_serial_rx_chars_dma() will
call s3c64xx_start_rx_dma() and enable_rx_dma(), restarting RX DMA after
s3c24xx_serial_stop_rx() has already stopped reception and terminated the
channel.

When S3C2410_UTRSTAT_TIMEOUT is set, neither s3c24xx_serial_stop_rx() nor
s3c24xx_serial_rx_dma_complete() (when skipping s3c64xx_start_rx_dma()
because ourport->rx_enabled is 0) resets ourport->rx_mode from
S3C24XX_RX_DMA. Could s3c24xx_serial_rx_chars_dma() then query
dmaengine_tx_status() on a dma->rx_cookie that was already completed or
terminated (where state.residue is 0) and copy dma->rx_bytes_requested
(PAGE_SIZE) bytes of stale data from dma->rx_buf into the tty flip buffer?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261031004217.3340610-1-samarth.colleges@gmail.com?part=2

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

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31  0:42 [PATCH 0/2] tty: serial: samsung: RX DMA fixes in stop_rx and the RX completion Samarth Narang
2026-10-31  0:42 ` [PATCH 1/2] tty: serial: samsung: pause the RX DMA channel in stop_rx Samarth Narang
2026-10-31  0:45   ` sashiko-bot
2026-10-31  0:42 ` [PATCH 2/2] tty: serial: samsung: do not re-arm RX DMA once RX has been stopped Samarth Narang
2026-10-31  1:03   ` 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=sashiko-outbox-191689@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=samarth.colleges@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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